samedi 26 avril 2014

Maven - ne peut pas compiler différentes java version - Stack Overflow


I have a multimodule maven project. I do a mvn clean install of one of its examples which downloads and installs some dependencies.


if I do a $ file WhateverClass.class in certain jars from my WEB-INF/lib downloaded and compiled by Maven I keep getting


WhateverClass.class: compiled Java class data, version 51.0

which means that class has been compiled with Java 7.


I get this no matter how many times I compile that module by itself first! Why? I have also checked the .class files from the modules themselves, after I see how the target folder has just been generated.


Along the project, some of the POM.xml specify a


<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>

but there are none specifying a higher java version.


My java version is:


java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10)
OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)

and javac version:


javac 1.6.0_23

EDIT


Here is my effective-pom




When you have problems like that, try to isolate the problem. The first step is to follow the path of the JAR backwards: Where did you find the class? Where did that JAR come from? If it came from a WAR, where did that come from? Do this until you find the computer on which the .class file is compiled. Check the JAR and the .class files in the target/classes/ folder.


At each step, run file on WhateverClass.class and go one step further when you see Java 7.


When you have find the build computer, you can use the following options to debug the build process:



  • mvn -v shows you the version of Maven and Java.

  • mvn help:effective-pom shows the resolved POM (i.e. after including every parent POM, resolving all properties, you name it). Which target option is active?

  • Run mvn with -X to get debug output. This can help to see which options Maven passes to forked processes.



I have a multimodule maven project. I do a mvn clean install of one of its examples which downloads and installs some dependencies.


if I do a $ file WhateverClass.class in certain jars from my WEB-INF/lib downloaded and compiled by Maven I keep getting


WhateverClass.class: compiled Java class data, version 51.0

which means that class has been compiled with Java 7.


I get this no matter how many times I compile that module by itself first! Why? I have also checked the .class files from the modules themselves, after I see how the target folder has just been generated.


Along the project, some of the POM.xml specify a


<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>

but there are none specifying a higher java version.


My java version is:


java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10)
OpenJDK Client VM (build 20.0-b11, mixed mode, sharing)

and javac version:


javac 1.6.0_23

EDIT


Here is my effective-pom



When you have problems like that, try to isolate the problem. The first step is to follow the path of the JAR backwards: Where did you find the class? Where did that JAR come from? If it came from a WAR, where did that come from? Do this until you find the computer on which the .class file is compiled. Check the JAR and the .class files in the target/classes/ folder.


At each step, run file on WhateverClass.class and go one step further when you see Java 7.


When you have find the build computer, you can use the following options to debug the build process:



  • mvn -v shows you the version of Maven and Java.

  • mvn help:effective-pom shows the resolved POM (i.e. after including every parent POM, resolving all properties, you name it). Which target option is active?

  • Run mvn with -X to get debug output. This can help to see which options Maven passes to forked processes.


0 commentaires:

Enregistrer un commentaire