配置Maven以将不同的JDK用于不同的J2SE版本? [英] Configure Maven to use different JDK for different J2SE versions?
问题描述
我想配置Maven2以使用sun-java6-jdk来构建Java SE 1.6模块,并使用openjdk-7来构建Java SE 1.7模块.有可能吗?
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应该自动选择正确的JDK以在一个命令中构建不同的模块.
Maven2 should then auto choose the correct JDK to build different modules in one command.
例如,应该是
$ mvn package
代替
$ cd module1
$ update-alternatives ... jdk6 ...
$ mvn package
...
$ cd module2
$ update-alternatives ... jdk7 ...
$ mvn package
P.S.与pom.xml文件无关,这些文件已经使用不同模块的<source>
和<target>
值设置了maven-compiler-plugin
.如果选择使用openjdk-7,则Maven2将生成版本1.6的类文件,但将使用openjdk-7而不是sun-java6-jdk.问题是关于如何配置Java SE配置文件.
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.
推荐答案
我们通过在编译插件的配置中明确分隔javac(将JAVA_HOME_6和JAVA_HOME_7定义为环境变量)来解决此问题:
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):
以及Java 6模块
<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>
以及Java 7模块
<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>
这篇关于配置Maven以将不同的JDK用于不同的J2SE版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!