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

RSS Feed for This PostPost a Comment