1

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!

2
  • I've also tried to open the .java file in notepad++ and set the encoding to UTF-8 with no luck. Commented Nov 24, 2016 at 16:51
  • Try to use <encoding>ISO-8859-1</encoding> Commented Nov 24, 2016 at 16:55

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

5 Comments

@Jose Or update Surefire, because this is a bug. You shouldn't need to set the file encoding: see issues.apache.org/jira/browse/SUREFIRE-951
After trying all other options as mentioned above, this one worked for me too. In my case it was an ecoding issue (Characters: Ä, Ü, Ö) with JUnit under Windows.
I had this issue even with surefire 2.22.2 but the above plugin configuration still worked for me. Thanks!
I set -Dfile.encoding=UTF-8 via JAVA_TOOL_OPTIONS, but maven-surefire-plugin ignores it. This answer worked for me.
and if you are using jacoco you should consider this stackoverflow.com/questions/23190107/…
1

I tried all settings mentioned in this post to build my project successfully however that didn't work for me. At last I was able to build my project successfully with mvn -DargLine=-Dfile.encoding=UTF-8 clean insall command.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.