Maven3.3.9安装过程中出现Unsupported major.minor version解决方法

Maven3.3.9安装过程中出现Unsupported major.minor version解决方法

Maven3.3.9默认需要使用jdk版本不小于jdk1.7版本,由于电脑用的jdk是1.6版本的,结果出现了如下错误:

C:Usersasus>mvn

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/ma

ven/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:14

1)

        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(Cl

assRealm.java:401)

        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(

SelfFirstStrategy.java:42)

        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadCl

ass(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(Launch

er.java:144)

        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun

cher.java:266)

        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav

a:229)

        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La

uncher.java:415)

        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:

356)

 

尽管按照官方文档上配置了toolchains.xml

<toolchain>

    <type>jdk</type>

    <provides>

      <version>1.7</version>

      <vendor>sun</vendor>

    </provides>

    <configuration>

      <jdkHome>C:Program FilesJavajdk1.7.0_55</jdkHome>

    </configuration>

  </toolchain>

 

  <toolchain>

    <type>jdk</type>

    <provides>

      <version>1.6</version>

      <vendor>sun</vendor>

    </provides>

    <configuration>

      <jdkHome>C:Program Files (x86)Javajdk1.6.0_24</jdkHome>

    </configuration>

  </toolchain>

 

pom.xml:

...

 <plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-toolchains-plugin</artifactId>

    <version>1.1</version>

    <executions>

      <execution>

        <goals>

          <goal>toolchain</goal>

        </goals>

      </execution>

    </executions>

    <configuration>

      <toolchains>

        <jdk>

          <version>1.7</version>

          <vendor>sun</vendor>

        </jdk>

      </toolchains>

    </configuration>

  </plugin>

  ...

然而依然如此,既然无法解决,只好换个思路了。

直接编辑mvn.cmd,找到开始校验位置添加如下路径,这样就不影响其他项目使用的jdk1.6了

@setlocal

set "JAVA_HOME=C:Program FilesJavajdk1.7.0_55"

 

也就是说,直接通过自定义设置,不在使用环境变量配置的全局java_home了

本页地址:http://www.easytd.com/yichangjijin/d_16012609269.html

转自:http://www.easytd.com/yichangjijin/d_16012609269.html

posted @ 2017-01-12 10:49  N神3  阅读(1179)  评论(0编辑  收藏  举报