maven,pom中的JAVA_HOME

问题描述 投票:0回答:1

我有 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>
maven
1个回答
0
投票

看看如何修复java.lang.UnsupportedClassVersionError:不支持的major.minor版本 安装 JRE 7 就可以了(maven 是构建工具,而不是运行时工具)

© www.soinside.com 2019 - 2024. All rights reserved.