我想配置Maven2使用sun-java6-jdk构建Java SE 1.6模块,并使用openjdk-7构建Java SE 1.7模块.可能吗?
然后Maven2应该自动选择正确的JDK来在一个命令中构建不同的模块.
例如,它应该是
$ mvn package
Run Code Online (Sandbox Code Playgroud)
代替
$ cd module1
$ update-alternatives ... jdk6 ...
$ mvn package
...
$ cd module2
$ update-alternatives ... jdk7 ...
$ mvn package
Run Code Online (Sandbox Code Playgroud)
PS这是一无所知的pom.xml文件,这些文件已经设置maven-compiler-plugin不同<source>,<target>价值观不同的模块.如果我选择使用openjdk-7,Maven2将生成1.6版本的类文件,但是使用openjdk-7而不是sun-java6-jdk.问题是如何配置Java SE配置文件.
我已经设置了我的pom文件,要求Maven使用source和targetconfig参数将我的源代码编译为兼容版本1.5 .这是我的pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com</groupId>
<artifactId>user</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
我有一个像这样的简单主类:
package com.user;
public class Test
{
public static void main(String[] argv)
{
System.out.println("".isEmpty());
}
}
Run Code Online (Sandbox Code Playgroud)
String#isEmpty()从Java 1.6开始引入.但是,编译我的代码与mvn compile工作,虽然我会期望它失败,因为我已经设置Maven将我的代码编译为Java 1.5并String#isEmpty在Java 1.6中引入.任何人都可以建议我可能做错了什么?在编译时强制Maven使用特定Java版本的正确方法是什么?
有关信息,我使用Apache Maven 2.2.1和javac 1.6.0_19.
谢谢.
由于scala 2.9.2项目与java 8版本之间不兼容,我需要在我的maven项目中手动指定jvm用法.
pom.xml中我做,用文档在这里:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.netlogo.extension</groupId>
<packaging>jar</packaging>
<artifactId>rungekuta</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${lib.org.scala-lang.scala.version}</version>
</dependency>
<dependency>
<groupId>org.nlogo</groupId>
<artifactId>netlogo</artifactId>
<version>5.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<lib.org.scala-lang.scala.version>2.9.3</lib.org.scala-lang.scala.version>
<maven.scala.version>${lib.org.scala-lang.scala.version}</maven.scala.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifestEntries>
<Extension-Name>rungekuta</Extension-Name>
<Class-Manager>org.netlogo.extension.rungeKuta.RungeKutaExtension</Class-Manager>
<NetLogo-Extension-API-Version>5.0</NetLogo-Extension-API-Version>
</manifestEntries> …Run Code Online (Sandbox Code Playgroud)