-->

Compile maven projects with JDK 1.6 in Eclipse Mar

2019-05-23 10:55发布

问题:

I need older version of m2e because I need to use older maven version (I have to compile some projects with JDK 1.6).

Here the exception when launch any build (with java 1.6) in Mars:

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:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
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)

Same problem if install external maven component, because the problem should be the new m2e plugin, compiled with JDK 1.7.

Any suggestions?

Here a related problem.

Regards.

回答1:

Download an version of Maven which support JDK 6 or hight, you can see in Maven Release History. I downloaded version 3.2.5.

After that open Eclipse Mars > Window > Preferences > Maven > Installations and add Maven 3.2.5, that click Apply then OK



回答2:

Go back to Luna. Seriously. =)

Do you really wanna try Mars? Ok, go on...

Firstly, download an eclipse version for non-java devs (for c/c++ devs should do the trick).

Secondly, install the "Eclipse Java Development Tools" package (select "Install New Software..." under the "Help" menu). Restart eclipse.

Now, open the same window again. Add the repository from m2e project (http://download.eclipse.org/technology/m2e/releases), uncheck "Show only the latest versions of available software" and check the higher 1.5.x version from m2e plugin (currently 1.5.2.20150414-2215). Restart eclipse again.

Enjoy (and good luck).



回答3:

m2e plugin in version >= 1.6 does not support Maven 2. If you want to install m2e plugin 1.5.x in Eclipse Mars with m2e 1.6 already installed (see row "Maven Integration for Eclipse" at. https://eclipse.org/downloads/compare.php?release=mars) you should:

  1. download Eclipse Luna Package with "Maven Integration for Eclipse" installed;
  2. copy all jars and directories from

    ${eclipse_luna}\plugins
    

    starting with org.eclipse.m2e prefix to

    ${eclipse_mars}\plugins;
    
  3. in

    ${eclipse_mars}\configuration\org.eclipse.equinox.simpleconfigurator\bundles.info
    

    remove all lines starting with org.eclipse.m2e prefix and copy-paste all lines starting with org.eclipse.m2e from

    ${eclipse_luna}\configuration\org.eclipse.equinox.simpleconfigurator\bundles.info
    

Remember not to update "Maven Integration for Eclipse" feature, because it will probably overwrite above changes.