我有 Maven 2.2.1,它使用 JAVA 1.6。但我需要用 1.7 编译和执行我的项目。我不想因为其他项目而更改 JAVA_HOME 变量,据我所知,我可以在 pom.xml 中配置它。
使用下面的代码,我可以编译我的项目,但由于版本较小,我无法执行它。我做错了什么?或者在pom中不可能做到这一切?或者它与maven版本(2.2.1)有关。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
<executable>...path-to-my-1.7-javac...</executable>
<compilerVersion>1.7</compilerVersion>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
编辑:使用 Maven-EXEC-PLUGIN 的解决方案
通过添加以下配置解决了问题:
<properties>
<arg0>defaultParam1</arg0>
</properties>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>path-to-java-1.7/bin/java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>${main.class}</argument>
<argument>${arg0}</argument>
</arguments>
</configuration>
</plugin>