Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven project source encoding does not work

I am having a Maven-Project which is configured using the following properties:

<properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>

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

On my machine everything works fine with these settings. However, on another machine, when I check it out and try to build it using mvn install the compiler errors unmappable character for encoding ASCII:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project scuttle: Compilation failure: Compilation failure:
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/handlers/sakai/SakaiVV.java:[99,39] error: unmappable character for encoding ASCII
[ERROR] 
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/handlers/sakai/SakaiVV.java:[99,40] error: unmappable character for encoding ASCII
[ERROR] 
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/domain/sakai/SakvvTermin.java:[66,30] error: unmappable character for encoding ASCII
[ERROR] 
[ERROR] /export/local-1/julian-downloads/scuttle/src/main/java/de/fu/mi/scuttle/domain/sakai/SakvvTermin.java:[66,31] error: unmappable character for encoding ASCII

I've already tried running mvn with -Dfile.encoding=UTF-8 but that did not help. $LC_CTYPE reports UTF-8.

What can I do?

You can see the complete pom file here: https://github.com/scravy/scuttle/blob/master/pom.xml

like image 434
scravy Avatar asked Oct 21 '13 13:10

scravy


3 Answers

In the end the comment by khmarbaise helped me find a solution:

I configured the compiler plugin and specified the source encoding there, now everything works everywhere:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>2.3.2</version>
      <configuration>
        <source>1.7</source>
        <target>1.7</target>
        <encoding>UTF-8</encoding>
      </configuration>
    </plugin>
  </plugins>
</build>
like image 150
scravy Avatar answered Oct 27 '22 15:10

scravy


You have all the right settings in your pom, so that's good. Verify your IDE (and the others used by your team if applicable) is configured for UTF-8.

Next, clean out your local .m2 repository and run your build again. It might be possible one of your transitive dependencies wasn't compiled with the right encoding. But you may have the "right" version in your .m2 that makes everything OK while the same version doesn't exist on the other machine.

Good luck! I know how annoying this stuff can be.

like image 25
Vidya Avatar answered Oct 27 '22 16:10

Vidya


Instead of setting maven opts, set new environmental variable - JAVA_TOOL_OPTIONS = -Dfile.encoding=UTF8

like image 35
BSeitkazin Avatar answered Oct 27 '22 15:10

BSeitkazin