Java,Ant错误:用于编码Cp1252的不可映射字符 [英] Java, Ant error: unmappable character for encoding Cp1252

查看:720
本文介绍了Java,Ant错误:用于编码Cp1252的不可映射字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用Java,Eclipse和Ant。我有一些Java代码,我需要编辑和添加一些UTF-8字符。以前我的build.xml有:

它工作正常。现在在我尝试运行后添加了这些UTF-8字符后,它会抛出错误:不可映射的字符用于编码Cp1252



有谁可以告诉我什么是修复?我尝试将编码更改为xml中的UTF-8和Cp1252,但没有运气。



我使用JRE7,Eclipse Kepler和Ant 4.11。

解决方案

p>这可能很棘手,只需更改广告编码就不能弥补文件中的字节无法用UTF-8解释来理解的事实。在Ant中,您将需要更新 javac 任务以添加如< javac ... encoding =utf-8>



确保Eclipse中的文件编码也是UTF-8,因为一些cp1252字符也不直接映射到UTF-8。您可能希望使用单个编码来维护整个项目。否则编译器将只看到不同的编码,只需要一个。


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.

解决方案

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.

这篇关于Java,Ant错误:用于编码Cp1252的不可映射字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆