RSS Feed for This PostCurrent Article

Maven: Compile Your Application to be JDK 1.4, 1.5 or 1.6 Compatible

I need to compile some of my Maven projects to be JDK 1.4 compatible, some for JDK 1.5 or JDK 1.6. To do this in Maven is very straight forward since I have different pom.xml for different applications.

I write my code using JDK 1.5 syntax but I need the library to be JDK 1.4 compatible, so here is my configuration.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.5</source>
        <target>jsr14</target>
    </configuration>
</plugin>

To compile it to be JDK 1.5 compatible,

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.5</source>
        <target>1.5</target>
    </configuration>
</plugin>

To compile it to be JDK 1.6 compatible
To compile it to be JDK 1.5 compatible,

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>


Trackback URL


RSS Feed for This Post3 Comment(s)

  1. Tom | Dec 18, 2008 | Reply

    Yeah that doesn’t completely work (as I just found out) because it doesn’t check runtime API compatibility. For instance, if you happen to use java.util.concurrent.* classes, it will still compile for a 1.4 source and target, and then barf at runtime when those classes are missing.

  2. Obaid Abdul Maroof | Jun 29, 2009 | Reply

    I am getting this error:
    annotations are not supported in -source 1.3
    (try -source 1.5 to enable annotations)
    I am using source and target version 1.5.
    any idea where am I wrong?

  3. Jane | Oct 27, 2009 | Reply

    I’m having this same problem. I’ve edited pom.xml to include source and target = 1.6, but it’s still barfing at compile time over 1.3 not supporting generics.

Sorry, comments for this entry are closed at this time.