0

This is a follow up to set file.encoding from pom.xml. I need to make sure that Charset.defaultCharset() returns UTF-8. When I run

JAVA_TOOL_OPTIONS='-Dfile.encoding=UTF-8' mvn clean compile test package

I get that. However, I do not have any control about how mvn is invoked, so I need to put something into pom.xml which would set the default charset to utf-8. Which systemPropertyVariables do I set?

EDIT: I do have

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

and

<configuration>
  <systemPropertyVariables>
    <file.encoding>${project.build.sourceEncoding}</file.encoding>
    <charset>${project.build.sourceEncoding}</charset>
  </systemPropertyVariables>
</configuration>

they do not help. defaultCharset is still US-ASCII.

Community
  • 1
  • 1
sds
  • 58,617
  • 29
  • 161
  • 278

2 Answers2

0

You can set the following property in the pom:

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

maven-compiler-plugin uses this property to set the Java compiler -encoding option.

See: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#encoding

ryanprayogo
  • 11,587
  • 11
  • 51
  • 66
0

You can try including that setting in the MAVEN_OPTS environment variable, examples in Maven Docs and stackoverflow.

Or, if you don't want to configure a global environment var, the Codehaus properties-maven-plugin might work too, depending on your use case.

Community
  • 1
  • 1
user944849
  • 14,524
  • 2
  • 61
  • 83