问题描述
我在我的项目中使用 Java、Eclipse 和 Ant.我有一些 Java 代码需要编辑并在其中添加一些 UTF-8 字符.以前我的 build.xml 有:它工作得很好.现在,当我尝试运行时添加这些 UTF-8 字符后,它会抛出错误:编码 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"
谁能告诉我解决方法是什么?我尝试将 xml 中的编码更改为 UTF-8 和 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.
我使用的是 JRE7、Eclipse Kepler 和 Ant 4.11.
I'm using JRE7, Eclipse Kepler and Ant 4.11.
推荐答案
这可能很棘手,仅更改广告"编码并不能弥补文件中存在使用 UTF- 无法理解的字节的事实-8 解释.在 Ant 中,您需要更新 javac
任务以添加编码,例如 <javac ... encoding="utf-8">
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">
请确保 Eclipse 中的文件编码也是 UTF-8,因为某些 cp1252 字符也不会直接映射到 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.
这篇关于Java、Ant 错误:编码 Cp1252 的字符不可映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!