0

I have two JDK - 1.5 and 1.6.
Default JDK is 1.6 (JAVA_HOME sets to JDK 1.6)
and have env. variable JAVA_HOME_1_5 sets to JDK 1.5

I want compile maven project with JDK 1.5, so I added to pom.xml next:

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-compiler-plugin</artifactId>  
    <configuration>  
      <fork>true</fork>  
      <executable>${env.JAVA_HOME_1_5}/bin/javac.exe</executable>  
      <showDeprecation>true</showDeprecation>  
      <showWarnings>true</showWarnings>  
      <optimize>true</optimize>  
      <source>1.5</source>  
      <target>1.5</target>  
    </configuration>  
  </plugin>

But maven is compiling my project with JDK 1.6! What is wrong?
Thanks in advance!

2
  • Did you try hardcoding the path to the 1.5 JDK ? ie <executable>/YOUR/PATH/bin/javac.exe</executable>
    – ndeverge
    Feb 15, 2012 at 8:28
  • Change to <executable>C:/tools/Java/jdk1.5.0_17/bin/javac.exe</executable> not helpful
    – Ilya
    Feb 15, 2012 at 8:34

3 Answers 3

1
%> JAVA_HOME=$JAVA_HOME_1_5 mvn install

Maven by default use JAVA_HOME so you can set it to jdk_1.5 just for it.

For pom way, you should add this:

<plugin>  
  <groupId>org.apache.maven.plugins</groupId>  
  <artifactId>maven-surefire-plugin</artifactId>  
  <configuration>  
    <jvm>${JAVA_HOME_1_5}/bin/java</jvm>  
    <forkMode>once</forkMode>  
  </configuration>  
</plugin>
0

Could it be because, as documented here, you are missing the <compilerVersion>1.5</compilerVersion> in your configuration?

0

can you try this. It works for me.

http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.