簡體   English   中英

從pom.xml設置`file.encoding`

[英]Set `file.encoding` from `pom.xml`

我將什么咒語放入pom.xml ,相當於

export JAVA_TOOL_OPTIONS='-Dfile.encoding=UTF-8'

.profile 我試過了

<configuration>
    <file.encoding>UTF-8</file.encoding>
</configuration>

maven-compiler-plugin

<properties>
    <file.encoding>UTF-8</file.encoding>
</properties>

在頂層,它沒有用。

主要思想是從pom.xml不是環境中進行設置(我無法控制將在什么環境下運行)。 同樣,我對修改.profile等的任何解決方案都不感興趣。

默認解決方案是使用以下方法:

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

maven-compiler-plugin具有不同的配置,尤其是使用上述屬性。

請嘗試以下操作:

    <configuration>
     ...
     <systemProperties>
        <systemProperty>
          <name>propertyName</name>
          <value>propertyValue</value>
        </systemProperty>
        ...
     </systemProperties>
    </configuration>

這應該工作。 至少它與其他Maven插件對我有用。

如果要在單元測試級別上指定編碼,則可以使用以下解決方案。 這是在插件啟動時設置的

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
      <skipTests>${skip.unit.tests}</skipTests>
      <enableAssertions>true</enableAssertions>
      <argLine>${surefireArgLine} -Dfile.encoding=UTF-8</argLine>
    </configuration>
  </plugin>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM