0

My machine has Java 1.7 installed:

> java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

>javac -version
javac 1.7.0_80

I have a Java 1.6 project I want to run, however when I go to build this project I get:

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.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)

I previously had Maven 3.3.9 installed, and I read somewhere Maven 3.2.5 was the last version of Maven to support Java 6, so I removed Maven 3.3.9 and installed Maven 3.2.5

>mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T09:29:23-08:00)
Maven home: /usr/local/Cellar/maven/3.2.5
Java version: 1.7.0_80, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.3", arch: "x86_64", family: "mac"

However when I go to build this 1.6 project, I still get the same major.minor version 51 exception thrown at me?

Any idea what's going on here? Any help or support would be much appreciated, thanks.

arabian_albert
  • 708
  • 1
  • 11
  • 24

2 Answers2

1

How can this be a 1.6 project if you're compiling it using JDK 1.7? The fact you're not using the new language features available in Java 7 does not imply you're producing bytecode targeting Java 6 VM's.

The solution would be to install the latest version of Maven and build your project as usual. If you want to target previous 1.6 VM's then set the source and target variables to 1.6 in the compiler plugin.

Roney Gomes
  • 497
  • 4
  • 13
  • Yes, I'm using that plugin to ensure my project is Java 6. But I think you're misunderstanding my question. My project is already Java 6, that's not an issue here. Read Thorbjørn's comment, you'll see my problem. But luckily I have a solution. Thanks for your help! – arabian_albert Mar 10 '16 at 21:06
  • Seems like it's the day of cross compilation, also check [this question/answer](http://stackoverflow.com/questions/35913775/maven-java-version-configuration-ignored-by-eclipse-idea) – A_Di-Matteo Mar 10 '16 at 21:07
  • 1
    @arabian_albert I'm glad you found a fix for it. All the best. :-) – Roney Gomes Mar 10 '16 at 21:07
0

The following worked for me.

I'm running Eclipse Mars 4.5.1, Java EE

Eclipse > Preferences > Installed JREs

Remove/Delete Java 1.6

Eclipse > Preferences > Installed JREs > Execution Environment

Under the Execution Environment Pane, Select JAVASE-1.6 and in the next Pane, check mark 1.6 Java. Repeat same steps for 1.7 (if you have Java 7 installed, under 1.7 it should say 'perfect match')

Thanks Thorbjørn for pointing me in the right direction

arabian_albert
  • 708
  • 1
  • 11
  • 24