How to set the file.encoding property at exec-maven-plugin?
-
14-11-2019 - |
Pergunta
I trying to exec my standalone application via exec-maven-plugin, but it started with WIN encoding, not UTF-8. I read about Java command line key -Dfile.encoding=UTF-8. How to set this property to my application? Thanx.
maven pom:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<mainClass>my.main.Class</mainClass>
</configuration>
</plugin>
Solução
According to the exec-maven-plugin documentation, it should look like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>my.main.Class</mainClass>
<commandlineArgs>-Dfile.encoding=UTF-8</commandlineArgs>
</configuration>
</plugin>
Outras dicas
To set encoding for mvn exec:java
, set MAVEN_OPTS
environment variable, e.g.:
export MAVEN_OPTS=-Dfile.encoding=utf-8
Here is what exec-maven-plugin usage page says:
Note: The java goal doesn't spawn a new process. Any VM specific option that you want to pass to the executed class must be passed to the Maven VM using the MAVEN_OPTS environment variable. E.g.
MAVEN_OPTS=-Xmx1024m
Otherwise consider using the exec goal.
more direct method than Todd's (his one's still cool though):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>my.main.Class</mainClass>
<systemProperties>
<systemProperty>
<key>file.encoding</key>
<value>UTF-8</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
samples here.