Enforcing an encoding for Eclipse in a maven project

In Maven it’s easy to set the encoding for your source code to a defined encoding (e.g. UTF-8) by inserting this part into your pom file:

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

But how to apply this to your Eclipse project?

Until now I committed some of the resources used by Eclipse to the repository to have a consistent behavior for all developers. For the encoding, this is the file “.settings/org.eclipse.core.resources.prefs” containing:

encoding/ =UTF-8
eclipse.preferences.version=1

Unfortunately the maven-eclipse-plugin doesn’t provide a property to set this when running “mvn eclipse:eclipse”.
But there is a generic that I found a while ago. With that it’s possible to create additional files for Eclipse. To automatically create the “.settings/org.eclipse.core.resources.prefs” containing the encoding defined in the maven pom, you can use this configuration:

org.apache.maven.plugins
maven-eclipse-plugin
2.8



.settings/org.eclipse.core.resources.prefs

=${project.build.sourceEncoding}
eclipse.preferences.version=1
]]>



And that even works using parent poms. So you only have to defin e that once for a project that consists of multiple Eclipse projects.

This entry was posted in Build, config and deploy, Eclipse Universe and tagged , , , . Bookmark the permalink.

Leave a Reply