Jose Climent Jose Climent - 11 days ago 6
Java Question

Maven install does not encode in UTF-8 even if configured

Hi I have a problem with the encoding of my project.

When I run JUnit tests from eclipse, there are no failures. The problem is when I do maven > clean maven > install, one of the tests fails.

I have this string: "ADMINISTRACIÓN", and it's fine when i run the JUnit from eclipse, but I've printed the variable and when maven does the tests, the value of this string is: "ADMINISTRACI�N".

I've changed every property I could find of encoding in eclipse to UTF-8.
-Configured the pom this way:

(...)
<project>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
(...)
</properties>
</project>
(...)
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
(...)


But the output is the same. I have a coworker that has the same project than me, and the same eclipse client and config, and her maven tests print accents with no trouble.

Any further ideas?

Thanks a lot!

Answer

Try run your build with:

mvn -DargLine=-Dfile.encoding=UTF-8 clean insall

if help, you can configure surefire in project:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
            </configuration>
        </plugin>

Problem may occur because System.out use default system encoding, you can change this be setting file.encoding java property.

Comments