0
我有Maven 2.2.1,它使用JAVA 1.6。但我需要用1.7来编译和执行我的项目。我不想因为其他项目而改变JAVA_HOME变量,据我所知,我可以在POM中进行配置。maven,JAVA_HOME pom
有了下面的代码,我可以编译我的项目,但由于次要版本,我无法执行它。我做错了什么?还是不可能在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 SOLUTION
问题解决了添加以下配置:
<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>
我已经安装了java 7,就像我在我的问题中所说的。它会工作,如果java_home指向java 1.7。,但我不想改变它。我想强制使用1.7。在这个特殊的项目在POM。当然,你可以从maven运行java代码。我试图用exec-plugin和builded jar来执行代码。它可以与JAV_HOME = 1.7一起工作。 – Salvadora 2013-04-08 17:56:55
@Salvadora安装它无w/o改变JAVA_HOME ...说出你JRE7在c:\ temp \ Foo所有你需要做的就是调用c:\ temp \ Foo \ java -jar \ builder.jar –
2013-04-08 17:59:02
Shmil,感谢您的重播。我知道,如果我在终端上给出jre的路径,我可以执行我的代码。但那是我想避免的。也许这是不可能的,当我使用jar时,但至少当我使用exec:java(maven-exec-plugin)时。我可以配置exec-plugin来做到这一点吗? – Salvadora 2013-04-08 18:47:13