Reputation: 451
I were doing Spring-boot project with my friend on java 7. It works fine. However, they decided to put it on java 6 server. So we have to change it. On my friend's laptop it works fine, but mine didn't. I don't know why it comess to be like this.
I've searched some, and found many root-cause is when you compile with higher version (java 7 for example) and run it on java 6. But what it comes to me, it runs fine when I run the project as Spring-Boot app on STS (which is on java 6 JRE):
But when I need it to become jar (which I do maven build/maven clean):
Here is the full log:
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)
I wonder what is wrong with this compiler? Here are some links that I've read:
Spring Boot - Unsupported major.minor version 51.0
Unsupported major.minor version 51.0 OpenShift
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
Why am I getting Unsupported major.minor version 51.0
java.lang.UnsupportedClassVersionError Unsupported major.minor version 51.0
https://stackoverflow.com/questions/36106755/unsupported-major-minor-version-51-0
Unsupported major.minor version 51.0 but everything is set to JDK 1.6
I've suspected this has to be with my configuration in STS, or my laptop, because my friend is also using STS, and it worked fine. I have done this suggestion:
Java 6 Unsupported major.minor version 51.0
But still the error persists. Any suggest will be appreciated.
Upvotes: 1
Views: 7421
Reputation: 26868
Make sure you follow the instructions when you want to use Java 6 with Spring Boot:
http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-use-java-6
(That said, you really should not be using Java 6 anymore. Even Java 7 has no more public updates since April 2015)
Upvotes: 0
Reputation: 451
It turns out to be, My Friend didn't change the Java compiler at all. They just change Java Version on Pom.xml:
And somehow it runs well on our Java 6 Server.
So, in addition with jens and abarisone comments, Spring-boot and/or it's dependencies need java 7 or more, but when we compile it(with java 7) with target set to java 6, it compiles, and surprisingly runs on java 6 machine. Can somebody explain it why? is it just luck or what?
Upvotes: 2