How to set the file.encoding property at exec-maven-plugin?

3.5k views Asked by At

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

There are 3 answers

0
Todd On BEST ANSWER

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>
0
br2000 On

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.

0
vucalur On

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.