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