Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building JARs with different JDK versions through Maven

Tags:

java

maven

We are currently busy upgrading to Java 1.7. Unfortunately, as these things go, a number of applications cannot be compiled under 1.7 and breaks (even with the override flag passed to 1.7). The plan is to re-factor these asap.

I would like to configure Maven in such a way that different JDKs can be used based on some property in the POM. I followed http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html to the letter, but no matter what I do, maven ignores the java specified in the POM.

The POM has the following entry:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <fork>true</fork>
                <source>1.6</source>
                <target>1.6</target>
                <compiler-version>1.6</compiler-version>
                <executable>/usr/lib/jvm/java-6-openjdk/bin/javac</executable> 
                <debug>true</debug>
                <verbose>true</verbose>
            </configuration>
        </plugin>
...

Furthermore, I get no output from the 'verbose' flag -- which I find odd. Maybe the above is completely ignored?

EDIT: I know it is not working, since inspecting the META-INF/MANIFEST.MF file shows the incorrect java version. The version used corresponds with the javac in the current path.

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: jaco
Build-Jdk: 1.7.0_147-icedtea
Implementation-Title: xxx
Implementation-Vendor: xxx
Implementation-Version: 1.3.7
Specification-Title: xxx
Specification-Vendor: xxx
Specification-Version: 1.3.7

EDIT: Something else that is rather interesting. If I purposefully break the file reference in , I get:

[INFO] Compilation failure
Failure executing javac,  but could not parse the error:
/bin/sh: /usr/lib/jvm/java-6-openjdk: Permission denied

EDIT: I suspect the problem lies with the component building the manifest file. If I break java 7 on my machine (i.e. rename javac to javac.pleasegoaway), it compiles!! However, the manifest files still reports version 1.7. This is now past annoying and getting hilarious.

Some help will be greatly appreciated, thanks.

like image 509
Jaco Van Niekerk Avatar asked Jun 26 '12 15:06

Jaco Van Niekerk


1 Answers

compiling and jar-ing are 2 separate operations. the fact that complation errors when you change the compiler path indicates that compilation is happening correctly. most likely the maven jar plugin is using the java7 jar tools to create the jar file.

like image 162
jtahlborn Avatar answered Oct 02 '22 14:10

jtahlborn