Loading...

Thursday, April 2, 2009

Change character encoding scheme for Maven resource and compile plugin in NetBeans

In a previous post we have learned how to change the source version for the Maven compiler plugin. But we can also change the character encoding scheme from the same Project Properties dialog window. The Encoding select box let's us change the encoding for the Maven project.

NetBeans add an encoding element to the compiler plugin definition and adds a configuration for the resource plugin in the pom.xml.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>

3 comments:

Dominic Mitchell said...

That's not 100% ideal… In Maven 2.1 you can have a project/build/sourceEncoding element, which specifies the default for all plugins.

In previous versions of Maven, you can add a property project.build.sourceEncoding which does the same thing for most plugins. I think the compiler plugin is the only one which ignores it.

See POM Element for Source File Encoding on the maven wiki for details.

mrhaki said...

The NetBeans 6.7 nightly release uses the project.build.sourceEncoding property.

atik khan said...

Perfect Homes is a new and vibrant internet property agency based in Chiang Mai, currently listing
both good rental and properties for sale in and around Chiang Mai area.

Post a Comment