错误:用于在maven编译期间编码UTF8的不可映射字符 [英] Error: unmappable character for encoding UTF8 during maven compilation

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

问题描述

我正在使用maven编译一个包,它说编译失败与下面的编译错误:



SpanishTest.java [31,81] unmappable character for encoding UTF8

我在线搜索,对许多人,更改源编码从UTF-8到ISO-8859-1似乎工作,但我仍然得到相同的编译错误。我使用32位Ubuntu。

 < project.build.sourceEncoding> ISO-8859-1< project.build.sourceEncoding> 

即使我更改< project.build.outputEncoding> 标签为ISO-8859-1,我仍然得到错误。它是否是因为java版本?我在我的系统上安装了双方的java和openjdk。



任何人都可以让我知道该怎么做。



感谢

解决方案

将maven-compiler-plugin配置为使用与源文件编码相同的字符编码例如):

 < plugin> 
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 2.3.2< / version>
< configuration>
< source> 1.6< / source>
< target> 1.6< / target>
< encoding> UTF-8< / encoding>
< / configuration>
< / plugin>

许多maven插件将默认使用project.build.sourceEncoding属性, pom将覆盖大多数插件。

 < project> 
< properties>
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< / properties>
...

但是,我更喜欢在每个插件的配置中设置编码因为我喜欢明确。



当你的源代码由maven-compiler-plugin编译时,你的源代码文件将由编译器插件使用任何编码编译器插件配置。如果源文件的编码与编译器插件使用的编码不同,那么这两种编码中可能不存在某些字符。



许多人喜欢设置编码将其源文件转换为UTF-8以避免此问题。要在Eclipse中执行此操作,您可以右键单击项目并选择Properties-> Resource-> Text File Encoding并将其更改为UTF-8。这将编码所有的源文件在UTF-8。 (你还应该明确配置上面提到的maven-compiler-plugin来使用UTF-8编码。)对于使用相同编码的源文件和编译器插件,在编译期间不应该有更多不可映射的字符。注意,您还可以通过Window-> Preferences-> General-> Workspace-> Text File Encoding在eclipse中全局设置文件编码。您还可以通过Window-> Preferences-> General-> Content Types来设置每个文件类型的编码。


I am compiling a package using maven and it says build failure with following compilation error:

SpanishTest.java[31, 81] unmappable character for encoding UTF8

I searched online and for many people, changing source encoding from UTF-8 to ISO-8859-1 seems to work but I am still getting same compilation error. I am using 32-bit Ubuntu. Here is how that tag looks in my pom.xml

<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>

Even if I change <project.build.outputEncoding> tag to ISO-8859-1, I still get the error.Could it be because of java version? I have both-sun java and openjdk installed on my system.

Can anyone please let me know what to do.

Thanks

解决方案

Configure the maven-compiler-plugin to use the same character encoding that your source files are encoded in (e.g):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>

Many maven plugins will by default use the "project.build.sourceEncoding" property so setting this in your pom will cover most plugins.

<project>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
...

However, I prefer setting the encoding in each plugin's configuration that supports it as I like to be explicit.

When your source code is compiled by the maven-compiler-plugin your source code files are read in by the compiler plugin using whatever encoding the compiler plugin is configured with. If your source files have a different encoding than the compiler plugin is using then it is possible that some characters may not exist in both encodings.

Many people prefer to set the encoding on their source files to UTF-8 so as to avoid this problem. To do this in Eclipse you can right click on a project and select Properties->Resource->Text File Encoding and change it to UTF-8. This will encode all your source files in UTF-8. (You should also explicitly configure the maven-compiler-plugin as mentioned above to use UTF-8 encoding.) With your source files and the compiler plugin both using the same encoding you shouldn't have any more unmappable characters during compilation.

Note, You can also set the file encoding globally in eclipse through Window->Preferences->General->Workspace->Text File Encoding. You can also set the encoding per file type through Window->Preferences->General->Content Types.

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

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