Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java, Ant error: unmappable character for encoding Cp1252

I am using Java, Eclipse and Ant in my project. I had some Java code that I needed to edit and add some UTF-8 chars in them. Previously my build.xml had: And it worked fine. Now after adding those UTF-8 chars when I try to run, it throws "error: unmappable character for encoding Cp1252"

Could anyone please tell me what is the fix? I tried changing the encoding to UTF-8 and Cp1252 in the xml but with no luck.

I'm using JRE7, Eclipse Kepler and Ant 4.11.

like image 812
user2666282 Avatar asked Apr 30 '14 23:04

user2666282


People also ask

How do I fix the Unmappable character for encoding cp1252?

Go to common tab of RUN/DEBUG configuration in eclipse change encoding to UTF-8. Show activity on this post. Window > Preferences > General > Content Types, set UTF-8 as the default encoding for all content types. Window > Preferences > General > Workspace, set "Text file encoding" to "Other : UTF-8".

What is cp1252 character encoding in Eclipse?

The default character encoding scheme in Eclipse is cp1252. You may be required to change this scheme, for example, if you intend to submit orders that contain character sets from languages such as Chinese, Japanese, or Norwegian. In this case, you can define the character encoding scheme as UTF-8.


2 Answers

This can be tricky simply changing the "advertised" encoding does not make up for the fact that there are bytes in the file that cannot be understood using a UTF-8 interpretation. In Ant you will need to update the javac task to add an encoding like, <javac ... encoding="utf-8">

Make sure that the file encoding in Eclipse is also UTF-8 because some cp1252 characters do not directly map into UTF-8 either. You will probably want to maintain your entire project using a single encoding. Otherwise the compiler will be seeing different encodings when it only expects one.

like image 189
Matthew M Avatar answered Sep 22 '22 15:09

Matthew M


You can try to set the environment variable called ANT_OPTS (or JAVA_TOOL_OPTIONS) to -Dfile.encoding=UTF8

like image 43
Andrea Luciano Avatar answered Sep 19 '22 15:09

Andrea Luciano