什么版本的 Maven 与 Java 6 兼容?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36141186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:29:10  来源:igfitidea点击:

What Version of Maven is Compatible with Java 6?

javamavenmaven-2

提问by James Oravec

I have to work in an older project that requires java 6 to run, as there are references to depreciated sun classes that have been removed in future versions. As part of the process, I changed my jdk from 8 in my system path to point to java 6 jdk. After doing so I get:

我必须在一个需要运行 java 6 的旧项目中工作,因为有对已在未来版本中删除的折旧 sun 类的引用。作为该过程的一部分,我将系统路径中的 jdk 从 8 更改为指向 java 6 jdk。这样做后,我得到:

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##代码##0(URLClassLoader.java:58)
    at java.net.URLClassLoader.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) 

This is is similar to Maven Installation OSX Error Unsupported major.minor version 51.0and Exception in thread "main" java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)however I'm not looking to upgrade, I'm looking to find a version of maven that is compatible with java 6. Any ideas on which version is compatible and where I can download/install it from for mac?

这类似于Maven Installation OSX Error Unsupported major.minor version 51.0and Exception in thread "main" java.lang.UnsupportedClassVersionError: a (Unsupported major.minor version 51.0)但是我不打算升级,我正在寻找找到与 java 6 兼容的 maven 版本。关于哪个版本兼容以及我可以从哪里下载/安装它 for mac 的任何想法?

采纳答案by M Anouti

According to the Maven release history page, the last Maven version that works with JDK1.6 is 3.2.5.

根据Maven 发布历史页面,与 JDK1.6 配合使用的最后一个 Maven 版本是 3.2.5。

Note that it's better to keep using the newer Maven version (and keep Java 8 as the default in the system path), and tell Maven that the project it's building should compile with source set to 1.6 - see source and target documentationfor more info. Reverting to an old Maven will remove the bug fixes / enhancements of the newer versions.

请注意,最好继续使用较新的 Maven 版本(并将 Java 8 保留为系统路径中的默认值),并告诉 Maven 它正在构建的项目应该在源代码设置为 1.6 的情况下进行编译 -有关详细信息,请参阅源代码和目标文档。恢复到旧 Maven 将删除新版本的错误修复/增强功能。

回答by khmarbaise

If you have the problem you need to build with JDK 6 but you would like run Maven with JDK 7 (cause you like to use Maven 3.3+) you should consider using toolchainwhich makes this independent from each other.

如果您遇到需要使用 JDK 6 构建的问题,但您希望使用 JDK 7 运行 Maven(因为您喜欢使用 Maven 3.3+),您应该考虑使用工具链,这使得它们彼此独立。