I want to have the encoding of my project's file to be set to UTF-8.
Following maven FAQ answer, I set the project.build.sourceEncoding
property to UTF-8. unfortunatly, it has no effect.
Then, by looking at a m2eclipse JIRA, I tried a workaround by defining compiler plugin sourceEncoding
, but it neither worked, as I try to do that in a separate module parent pom.
Then, what is the solution to ensure my files are all in UTF-8 from maven ?
Thanks.
In Eclipse, go to Preferences>General>Workspace and select UTF-8 as the Text File Encoding. This should set the encoding for all the resources in your workspace.
Building and Running the Maven Project in Eclipse To run the maven project, select it and go to “Run As > Java Application”. In the next window, select the main class to execute. In this case, select the App class and click on the Ok button. You will see the “Hello World” output in the Console window.
You can Launch Maven builds from within Eclipse. It does the dependency management for Eclipse build path based on Maven's pom. xml.
(A bit late) Solution / workaround I'm using to avoid inheriting MacRoman.
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalConfig>
<file>
<name>.settings/org.eclipse.core.resources.prefs</name>
<content>
<![CDATA[eclipse.preferences.version=1${line.separator}encoding/<project>=${project.build.sourceEncoding}${line.separator}]]>
</content>
</file>
</additionalConfig>
</configuration>
</plugin>
</plugins>
</build>
Execute the command below :
mvn eclipse:eclipse
Credits to Steven Cummings.
Just specifying
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
will do it.
It didn't use to work - hence the other answers - but this was fixed already back in 2011. For more details, see eclipse bug entry 343927.
Define Eclipse project encoding as UTF-8 from Maven
I don't know if you saw MNGECLIPSE-1782 but this is currently not supported, m2eclipse doesn't derive the project encoding from your POM. You'll have to set up the encoding manually under Eclipse (which can be done globally for the workspace via Preferences > General > Workspace).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With