2

What incantation do I put into pom.xml which will be equivalent to

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

in .profile? I tried

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

in maven-compiler-plugin and

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

in top level and it did not work.

The main idea is to set this from pom.xml, NOT from the environment (I have no control over what environment this will be run under). Again, I am not interested in any solution which modifies .profile et al.

sds
  • 58,617
  • 29
  • 161
  • 278
  • okay, I now know how to do **file.encoding=UTF-8**; alas, I still get **Charset.defaultCharset()** return **US-ASCII** instead of **UTF-8**. .. – sds Apr 30 '12 at 16:43

3 Answers3

6

The default solution is to use the following:

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

and the maven-compiler-plugin has a different configuration and in particular uses the above property.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
1

Try the following:

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

This should work. At least it works for me with other maven plugins.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • THANKS!! is there a way to set these for all plugins without having to repeat the systemProperties or [systemPropertyVariables](http://maven.apache.org/plugins/maven-surefire-plugin/examples/system-properties.html) block for each plugin? – sds Apr 30 '12 at 16:32
0

If you want to specify the encoding on unit test level you can use the following solution. This is set on startup of the plugin

 <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>