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:


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:


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:


=${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.

Short URL for this post: https://blog.oio.de/mXGe5
This entry was posted in Build, config and deploy, Eclipse Universe and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *