【问题标题】:Maven build error on MAcOS : " unmappable character for encoding UTF-8"MACOS 上的 Maven 构建错误:“用于编码 UTF-8 的不可映射字符”
【发布时间】:2014-06-15 02:46:53
【问题描述】:

我在 Eclipse Kepler 上开发 MacO。

我正在尝试使用 UTF8 运行 maven,以依赖于操作系统。

我想我已经尝试了很多似乎对其他人有效但对我无效的解决方案。

export JAVA _TOOL_OPTIONS -Dfile.encoding=UTF-8

当我在控制台中运行时:

mvn -version


Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100)
Maven home: /usr/share/maven
Java version: 1.6.0_45, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: fr_FR, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac"

但我正在通过 Eclipse 运行 maven,而 Eclipse 说平台编码 macRoman... 当我运行一个

全新安装

Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100)
Maven home: /Users/JP/git/CleanOmicsTracer/EMBEDDED
Java version: 1.6.0_45, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: fr_FR, platform encoding: MacRoman
OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac"

在我的 pom.xml 中,我设置为设置 UTF-8:

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

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <configuration>
            <tag>${project.build.finalName}</tag>
            <url>http://localhost:8080/manager/text</url>
            <server>localhost</server>
            <charset>UTF-8</charset>
            <update>true</update>
            <path>/${project.build.finalName}</path>
            <username>jp</username>
            <password>camille</password>
        </configuration>
    </plugin>

     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
        <source>${jdk.version}</source>
        <target>${jdk.version}</target>
        <encoding>${project.build.sourceEncoding}</encoding>
        <sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>

        <fork>true</fork>
            <meminitial>128m</meminitial>
             <maxmem>1024m</maxmem>
            <url>http://localhost:8080/manager/text</url>
            <server>localhost</server>
            <path>/${project.build.finalName}</path>
        </configuration>
    </plugin>


     <plugin>
     <artifactId>maven-resources-plugin</artifactId>
     <version>2.6</version>
     <configuration>
     <encoding>${project.build.sourceEncoding}</encoding>
     <sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
     </configuration>
     </plugin>

它不起作用,我的 .java 中的 é 和 è 会产生错误:

当我在 maven-compile-plugin 中更改这一行时

macRoman

,没关系,但不再依赖于 Os 并且字符会在我的 linux 中的另一台计算机中被误解。

当我全新安装时,输出对于资源来说是可以的,但编译器没有做任何事情:

[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ CleanOmicsTracer --- [INFO] 使用 'UTF-8' 编码复制过滤 资源。 [INFO] 复制 36 个资源 [INFO]

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ CleanOmicsTracer --- [INFO] 检测到更改 - 重新编译模块! [INFO] 编译 142 个源文件到 /Users/JP/git/CleanOmicsTracer/target/classes [信息]

[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ CleanOmicsTracer --- [INFO] 使用 'UTF-8' 编码以复制过滤的资源。 [INFO] 跳过不存在的 resourceDirectory /Users/JP/git/CleanOmicsTracer/src/test/resources

更新:我将 eclipse 配置更改为使用 /usr/share/maven 而不是嵌入式版本。 我仍然有错误,而这次平台编码设置为 UFT-8:

Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100)
Maven home: /usr/share/java/maven-3.0.4
Java version: 1.6.0_45, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: fr_FR, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac"

[ERROR] /com/clb/genomic/lyon/validator/ParticipantExistenceValidator.java:[101,93] unmappable character for encoding UTF-8
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: 
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project CleanOmicsTracer: Compilation failure

【问题讨论】:

  • 我删除了 org.apache.maven.plugins,现在可以了 :)

标签: java eclipse maven-3


【解决方案1】:

如果平台编码设置为 MacRoman 时可以正常工作,但设置为 UTF-8 时失败,则表示 ParticipantExistenceValidator 不是 UTF-8 编码。您需要修复文件,而不是配置。

一种简单的方法是使用native2ascii 两次,首先将MacRoman 转换为Unicode 转义符,然后再次使用-reverse 将转义符转换回UTF-8。

【讨论】:

    猜你喜欢
    • 2011-06-27
    • 2014-07-03
    • 2015-02-15
    • 2012-11-05
    • 1970-01-01
    • 2015-07-26
    • 2019-02-04
    • 2012-02-17
    相关资源
    最近更新 更多