简体   繁体   English

Maven eclipse插件使用Eclipse JRE而不是JAVA_HOME

[英]Maven eclipse plugin uses Eclipse JRE instead of JAVA_HOME

I upgraded to maven 3 . 我升级到了Maven 3 My projects are built using jdk6, so eclipse JRE points to java 6 home. 我的项目是使用jdk6构建的,因此Eclipse JRE指向java 6 home。 It appears that maven 3 requires java 7. My JAVA_HOME points to java 7, but Maven plugin apparently uses JRE 6 (Eclipse JRE), and throws this exception when run from eclipse: 看来maven 3需要Java7。我的JAVA_HOME指向Java 7,但是Maven插件显然使用了JRE 6(Eclipse JRE),并且在从eclipse运行时抛出此异常:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:401)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:254)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:144)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:266)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) 

How can I let m2eclipse use java7 (which is my JAVA_HOME)? 如何让m2eclipse使用java7(这是我的JAVA_HOME)?

Note that standalone maven works properly, but it's easier to run it from eclipse. 请注意,独立的Maven可以正常工作,但是从Eclipse运行它更容易。

set M2_HOME to you maven home, set JAVA_HOME, then set you path so at the beginning is 将M2_HOME设置为您的行家,设置JAVA_HOME,然后设置您的路径,因此开头是

   Path=%JAVA_HOME%/bin;%M2_HOME%/bin

If you're on windows this is set by start->right click on computer, properties->advanced system settings->environment variables. 如果您在Windows上,则通过开始->右键单击计算机,属性->高级系统设置->环境变量进行设置。

You also need to change you eclipse to use the java 1.7 jdk. 您还需要更改月食以使用Java 1.7 jdk。 That should take care of things, you can set the compile level in your eclipse/maven project to 1.6. 这应该会解决,您可以将eclipse / maven项目中的编译级别设置为1.6。

I were facing same issue with eclipse. 我在日食方面面临着同样的问题。 Adding below plugin to plugins list and rebuild project using Alt+F5 solved my problem. 在插件列表下面添加插件,并使用Alt + F5重建项目解决了我的问题。 Hope it will solve yours as well : 希望它也能解决您的问题:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
        <debug>true</debug>
        <verbose>true</verbose>
        <source>1.7</source>
        <target>1.7</target>
        <fork>true</fork>
    </configuration>
</plugin>

After rebuild eclipse will automatically select JRE1.7 if you have JRE1.7 configured in eclipse preferences. 重建后,如果您在eclipse首选项中配置了JRE1.7,eclipse将自动选择JRE1.7。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM