【问题标题】:Maven: setup compiler plugin encoding without editing pom.xmlMaven:设置编译器插件编码而不编辑 pom.xml
【发布时间】:2011-07-25 08:58:02
【问题描述】:

我正在尝试将我安装的 maven 3.0.3 设置为 Cp1252 编码。是否可以在不编辑 pom.xml 文件之一的情况下更改编码?也许在settings.xml 中为编译器插件创建一个配置文件?如果是,该怎么做?以下方法无效:

<settings>
...
 <profiles>
 <profile>
  <id>encoding</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
   <build>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <encoding>Cp1252</encoding>
        </configuration>
      </plugin>
    </build>
 </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>encoding</activeProfile>
  </activeProfiles>
</settings>

【问题讨论】:

    标签: encoding maven-plugin maven-3


    【解决方案1】:

    好的,我通过添加解决了问题

    -Dfile.encoding=CP1252
    

    到全局 MAVEN_OPTS

    【讨论】:

    • 这看起来像设置一个java vm属性,你确定它不会影响你的资源吗? (即尝试将 utf-8 xml 文件读取为 cp1252)。
    • 项目设置迫使我以这种方式解决它,这适用于 atm。我不知道更好的方法,也许你能帮忙?
    【解决方案2】:

    放入项目的根 pom 中:

    <properties>
        <project.build.sourceEncoding>cp1252</project.build.sourceEncoding>
    </properties>
    

    它为所有使用这个 pom 作为父级的子项目定义了它。否则,您的构建将无法重现。

    【讨论】:

    • 我读了这个问题。问题是如果父 pom 不会被更改并且编码将由系统属性完成,那么构建是不可重现的,这真的更糟。
    猜你喜欢
    • 2013-03-07
    • 1970-01-01
    • 2019-09-18
    • 2017-03-18
    • 2012-02-14
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多