Search code examples
javaantcompilationcompiler-errorsjavac

Ant error: unmappable character for encoding Cp1252


I am getting the following error when i build my project via ant.

ResourceManagerJDBCRAHA.java:40: error: unmappable character for encoding Cp1252  

If a ConnectionManager of type “JDBCxE2|x80? is found, it instantiates the class

This part of the code is actually a comment in my java file as following

/* If a ConnectionManager of type “JDBC” is found, it instantiates the class */

When i add single quotes instead of double quotes for JDBC (see below) i do not get this error

/* If a ConnectionManager of type 'JDBC' is found, it instantiates the class */

Following are the questions that i have:-

  1. Why is this happening?
  2. What can i do to resolve this i.e. by keeping the double quotes

I have tried adding encoding attribute like below which fixes the problem but gives rise to issues elsewhere

<javac .....  encoding="UTF-8"> .... </javac> 
error: unmappable character for encoding UTF-8

I would prefer to stick to the default i.e. without adding encoding attribute.


Solution

  • If you look carefully at that comment, you will see that there are actually two different kinds of double-quote characters there: (“) and ("). (I'm not entirely convinced that this matches your source code ... 'cos I haven't been able to de-mangle it.)

    The simple answer is to use ASCII double-quote characters exclusively.

    The more complicated answer is to make sure that you know what the character encoding of your files REALLY is, and then set that encoding in the build.xml file.


    I would prefer to stick to the default i.e. without adding encoding attribute.

    That is the best answer, but it requires you stick exclusively to using characters in the default character-set in your source code. Since you can never be entirely sure what the compilation platform's default character set will be ... stick to 7-bit ASCII, and this double-quote character: (").