【问题标题】:Maven project source encoding does not workMaven项目源编码不起作用
【发布时间】:2013-10-30 00:39:29
【问题描述】:

我有一个使用以下属性配置的 Maven 项目:

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>

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

在我的机器上,这些设置一切正常。但是,在另一台机器上,当我检查它并尝试使用mvn install 构建它时,编译器错误unmappable character for encoding ASCII

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project scuttle: Compilation failure: Compilation failure:
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/handlers/sakai/SakaiVV.java:[99,39] error: unmappable character for encoding ASCII
[ERROR] 
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/handlers/sakai/SakaiVV.java:[99,40] error: unmappable character for encoding ASCII
[ERROR] 
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/domain/sakai/SakvvTermin.java:[66,30] error: unmappable character for encoding ASCII
[ERROR] 
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/domain/sakai/SakvvTermin.java:[66,31] error: unmappable character for encoding ASCII

我已经尝试使用-Dfile.encoding=UTF-8 运行mvn,但这并没有帮助。 $LC_CTYPE 举报UTF-8

我能做什么?

您可以在此处查看完整的 pom 文件:https://github.com/scravy/scuttle/blob/master/pom.xml

【问题讨论】:

  • 您是否 100% 确定您的来源是 UTF-8 编码的?可能它们不是,但由于某种原因它可以在您的环境中工作(可能是您的 IDE 干扰)
  • 请更新你的 maven-compiler-version 因为 2.0.2 真的太旧了。目前我们有 3.1..
  • 与默认的 maven-compiler 插件 v2.0.2 有同样的问题。增加版本解决问题。

标签: java maven encoding utf-8


【解决方案1】:

最后,khmarbaise 的评论帮助我找到了解决方案:

我配置了编译器插件并在那里指定了源编码,现在一切正常:

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

【讨论】:

  • 很高兴您自己找到了解决问题的方法!
【解决方案2】:

您的 pom 中的所有设置都正确,这很好。验证您的 IDE(以及您的团队使用的其他 IDE,如果适用)配置为 UTF-8。

接下来,清理您的本地 .m2 存储库并再次运行您的构建。您的传递依赖项之一可能未使用正确的编码进行编译。但是您的 .m2 中可能有“正确”的版本,这使得一切正常,而另一台机器上不存在相同的版本。

祝你好运!我知道这些东西有多烦人。

【讨论】:

    【解决方案3】:

    不设置maven opts,而是设置新的环境变量-JAVA_TOOL_OPTIONS = -Dfile.encoding=UTF8

    【讨论】:

      猜你喜欢
      • 2014-03-09
      • 1970-01-01
      • 2017-05-05
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-18
      • 1970-01-01
      相关资源
      最近更新 更多