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

  4. Michel | Jul 6, 2010 | Reply

    For those who have the same problem as I had:
    If m2eclipse still configures J2SE 1.4 instead of the configured 1.6, make sure you don’t have pom configured in the affected projects.

  5. Michel | Jul 6, 2010 | Reply

    Argh HTML… I meant:
    <packaging>pom</packaging>

  6. Ankur | Jan 6, 2011 | Reply

    Hi Jane were you able to solve this problem ? Even I’m facing the same issue.

  7. blabla | Mar 26, 2012 | Reply

    In case it helps someone : you also need to change the JAVA_HOME environment variable : maven uses this one to locate the javac executable.

2 Trackback(s)

  1. From Compile Your Application to be JDK 1.4, 1.5 or 1.6 Compatible | Punit's Blog | Aug 30, 2010
  2. From TipTopia | Jul 25, 2011

RSS Feed for This PostPost a Comment

*