How to indicate the java compiler version and target version

By default, the maven will use the compiler source check level to 1.3 and target version to 1.1 for maximum artifact compatibility. However, in most of your project, you don’t need such compatibility. In contrast, you will want to use more recently language features: like assertion, generic type of container, and so on. You can do that be indicate the compiler source and target requirement.

First, from Eclipse IDE, select “maven – add plugin”, add the maven-compiler-plugin, the lastest version should be 2.02. This will add some elements to you pom.xml like:

...
<build>
  <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
      </plugin>
  </plugins>
</build>
...

you can add attibutes after version, like:

<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
    <source>1.6</source>
    <target>1.6</target>
</configuration>

This will set the source check and target check version to jre 6.0. You will notice that although sun has change this naming scheme from 1.x to x.0 from jre 5.0 on, but maven still using 1.x scheme.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Share/Bookmark

One Response to “How to indicate the java compiler version and target version”

  1. Albert Says:

    What’s up?. Thanks for the info. I’ve been digging around looking some info up for shool, but i think i’m getting lost!. Yahoo lead me here – good for you i guess! Keep up the great information. I will be coming back in a couple of days to see if there is any more info.

Leave a Reply