安装maven 3.3.3 在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:637) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) 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.Cla***ealm.loadClassFromSelf(Cla***ealm.java:401) at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42) at org.codehaus.plexus.classworlds.realm.Cla***ealm.unsynchronizedLoadClass(Cla***ealm.java:271) at org.codehaus.plexus.classworlds.realm.Cla***ealm.loadClass(Cla***ealm.java:254) at org.codehaus.plexus.classworlds.realm.Cla***ealm.loadClass(Cla***ealm.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)
网上查找说是jdk版本不对,51代表jdk7,应该在eclipse里将jdk改为1.6,但是改完以后(包括build path与compile都改为1.6)运行还是报同样错误
于是翻了下maven安装路径下的文件,在README.txt里发现这样一段话:
System Requirements ------------------- JDK: 1.7 or above (this is to execute Maven - it still allows you to build against 1.3 and prior JDK's). Memory: No minimum requirement. Disk: Approximately 10MB is required for the Maven installation itself. In addition to that, additional disk space will be used for your local Maven repository. The size of your local repository will vary depending on usage but expect at least 500MB. Operating System: Windows: Windows 2000 or above. Unix based systems (Linux, Solaris and Mac OS X) and others: No minimum requirement.
其中:
也就是说这个版本的maven必须要运行在jdk7或者更高版本的java环境中,注意这里说的是运行maven,并不表示在用mvn对工程build的时候必须用jdk7或者更高版本,build时依然支持各个版本的jdk.
但是maven与eclipse集成以后是根据项目的jdk配置来运行,所以无法指定运行maven与用maven编译时用不同版本的jdk.
如果非得用jdk6来编译项目,用jdk6来运行maven,那就下载更早版本的maven吧.
Apache 官网有关于maven各个版本对jdk的要求
System RequirementsJDK Maven 3.3 requires JDK 1.7 or above, Maven 3.2 requires JDK 1.6 or above, while Maven 3.0/3.1 requires JDK 1.5 or above (this is to execute Maven - it still allows you to build against 1.3 and prior JDK's: see our Guide to Using Toolchains)