31

when you run mvn --version part of the output includes the locale and pratform encoding. For example: Default locale: en_GB, platform encoding: Cp1252

I would like to know where it picks these up from and how they can be set

5 Answers 5

41

maven picking these values from Java system properties. Here is how you could set encoding:

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

Or:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <configuration>
      <encoding>UTF-8</encoding>
    </configuration>
  </plugin>

Or pass parameter to maven command line:

mvn -Dproject.build.sourceEncoding=UTF-8
Sign up to request clarification or add additional context in comments.

4 Comments

The best thing is to put such kind of information into the pom or into a company pom NEVER on command line.
It works in a pom.xml, but it doesn't answer the question of a global configuration for mvn --version
this first answer has 2 faults: it lacks setting project.reporting.outputEncoding, and even with that, it works for one pom only. If you have a serious project, you have to put those settings into POM in every module. The sensible global solution is stackoverflow.com/a/9976788/715269. The second answer is even worse. The last one is acceptable for work in Eclipse. So, it is not universal because of inconvenience.
If you give several answers, you should say in what case we should use which.
33

You could set environment information for maven (on a windows system) with

set "MAVEN_OPTS=-Duser.language=fr -Dfile.encoding=UTF-8"

2 Comments

@cdog, it would be nice if you mark this post as an answer so others would see it right away.
+1. Excellent. That is the only way to set the coding for all maven globally. Or we should create POM in every project and put two properties into every one - obvious nonsense.
11
set MAVEN_OPTS= -Dfile.encoding="UTF-8"

Actually it won't work, you need to remove the quotes ("") :

set MAVEN_OPTS= -Dfile.encoding=UTF-8

1 Comment

a least on cygwin you have to replace set with export & the value has to be quoted like : export MAVEN_OPTS=" -Dfile.encoding=UTF-8"
3

Best solution is:

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

More: http://www.sonatype.com/people/2009/11/special-character-encoding-properties/

1 Comment

3

I had the same problem. The only thing that works is to set the appropriate MAVEN_OPTS. So if you use windows you can adapt mvn.bat in %MAVEN_HOME%/bin as follows:

set MAVEN_OPTS=%MAVEN_OPTS% -Dfile.encoding="UTF-8"

Following this mvn -v shows this:

..
Default locale: de_DE, platform encoding: UTF-8
..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.