当我将 maven java 编译器插件从 1.5 更改为 1.6 时,为什么会得到一个不可映射的字符来编码 UTF-8?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7202235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:03:18  来源:igfitidea点击:

Why do I get an unmappable character for encoding UTF-8 when I changed maven java compiler plugin from 1.5 to 1.6?

javacompiler-constructionencodingmaven

提问by joragupra

I have a Java project and I'm using Apache Maven. All this time I was using Maven Java compiler plugin with parameters source=1.5and target=1.5defined in pom.xml file. Since I changed it to source=1.6and target=1.6I'm getting the following error:

我有一个 Java 项目,我正在使用 Apache Maven。一直以来,我都在使用 Maven Java 编译器插件,在 pom.xml 文件中定义了参数source=1.5target=1.5。由于我将其更改为source=1.6target=1.6,因此出现以下错误:

XXXXXXXX.java:[54,27] unmappable character for encoding UTF-8

XXXXXXXX.java:[54,27] 用于编码 UTF-8 的不可映射字符

I've been testing different configurations and I turned showWarningsto value trueso I could see that with value 1.5for sourceand targetthis is a warning and not an error.

我一直在测试不同的配置,并将showWarnings 设置true值,这样我就可以看到目标的值为1.5 时,这是警告而不是错误。

I need to change the Java compiler configuration anyway. Does anybody know why is this so and how can I solve this problem without editing all Java source files (there are hundreds of files with this issue now)?

无论如何,我需要更改 Java 编译器配置。有谁知道为什么会这样,我如何在不编辑所有 Java 源文件的情况下解决这个问题(现在有数百个文件存在这个问题)?

回答by Brian Clozel

My question is: why is this an error with source=1.6 and target=1.6 and it's a warning with source=1.5 and target=1.5?

我的问题是:为什么这是 source=1.6 和 target=1.6 的错误,它是 source=1.5 和 target=1.5 的警告?

Short anwser, because they said so:

简短的回答,因为他们是这么说的

-source 1.6 This is the default value. No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors, instead of warnings, as previously.

-source 1.6 这是默认值。Java SE 6 中没有引入任何语言更改。但是,源文件中的编码错误 现在报告为错误,而不是以前的警告

@DaveG concerns are valid, and you should try to:

@DaveG 的担忧是有效的,您应该尝试:

  • Change the file encoding of your source files
  • find/replace those chars with your IDE
  • 更改源文件的文件编码
  • 使用您的 IDE 查找/替换这些字符