Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make maven build class files with UTF-8 without using the external JAVA_TOOL_OPTIONS?

I don't want to be dependable on a external environment variable to force maven to build my classes with UTF-8. On Mac, I was getting all sorts of problems when building with maven. Only the option below solved the problem:

export JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
mvn clean install

However I am distributing my project and it does NOT make sense to rely on the user to set this environment variable to build the project correctly.

Tried everything as described here: enabling UTF-8 encoding for clojure source files

Anyone has a light on that awesome Maven issue?

like image 272
chrisapotek Avatar asked Apr 28 '12 23:04

chrisapotek


Video Answer


1 Answers

@Joop Eggen gave the right answer here: https://stackoverflow.com/a/10367745/962872

It is not enough to define that property. You MUST pass it inside the appropriate plugins. It won't go by magic inside there.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>...</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>...</version>
    <configuration>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>
</plugin>
...
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
like image 150
chrisapotek Avatar answered Oct 20 '22 16:10

chrisapotek