I want to configure Maven2 to use sun-java6-jdk to build Java SE 1.6 modules, and use openjdk-7 to build Java SE 1.7 modules. Is it possible?
Maven2 should then auto choose the correct JDK to build different modules in one command.
For example, it should be
$ mvn package
instead of
$ cd module1 $ update-alternatives ... jdk6 ... $ mvn package ... $ cd module2 $ update-alternatives ... jdk7 ... $ mvn package
P.S. It's nothing about pom.xml files, which have already been setup maven-compiler-plugin
with different <source>
, <target>
values for different modules. If I choose to use openjdk-7, Maven2 will generate version 1.6 class files, but using openjdk-7 rather then sun-java6-jdk. The question is about how to configure Java SE profiles.
You can set the JAVA_HOME parameter just before you start maven (and change it back afterwards if need be). You could also go into your mvn (non-windows)/ mvn. bat / mvn. cmd (windows) and set your java version explicitly there.
The Maven tool uses JDK version 11.0. 10. The default JDK is set to 13.0.
During the build of a project, Maven, without toolchains, will use the JDK to perform various steps, like compiling the Java sources, generate the Javadoc, run unit tests or sign JARs. Each of those plugins need a tool of the JDK to operate: javac, javadoc, jarsigner, etc.
we solved this problem by explicitely sepecify the javac in config of compile plugin (with JAVA_HOME_6 and JAVA_HOME_7 defined as environment variables):
and for Java 6 module
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> <showDeprecation>true</showDeprecation> <showWarnings>true</showWarnings> <executable>${env.JAVA_HOME_6}/bin/javac</executable> <fork>true</fork> </configuration> </plugin>
and for Java 7 module
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.7</source> <target>1.7</target> <showDeprecation>true</showDeprecation> <showWarnings>true</showWarnings> <executable>${env.JAVA_HOME_7}/bin/javac</executable> <fork>true</fork> </configuration> </plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With