Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define Eclipse project encoding as UTF-8 from Maven

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.

like image 780
Riduidel Avatar asked Oct 28 '10 14:10

Riduidel


People also ask

How do I change from encoding to UTF 8 in Eclipse?

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.

How do I run a project as Maven project in Eclipse?

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.

Can I use Maven in Eclipse?

You can Launch Maven builds from within Eclipse. It does the dependency management for Eclipse build path based on Maven's pom. xml.


3 Answers

(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.

like image 195
Adrian Avatar answered Oct 28 '22 05:10

Adrian


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.

like image 35
eis Avatar answered Oct 28 '22 06:10

eis


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).

like image 1
Pascal Thivent Avatar answered Oct 28 '22 06:10

Pascal Thivent