0

I have a spring boot REST API jar file which works perfectly fine when I run it in my local machine using eclipse IDE, however when I upload the jar file to my VPS server I get the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/JarLauncher : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

I changed the java version in my POM file from version 11 to java 8:

<properties>
    <java.version>8</java.version>
</properties>

In the VPS server I could see that the available java versions are: java 7 (Version : 7u80) and java 8 (Version : 8u92 - 1.8.0_92-b14), however my JRE version is jre 1.8.0_201.

If I keep java 7 in the VPS server I get the exception mentioned above and if I remove java 7 from the VPS server, then I get the following error when trying to run the jar file from ssh using Putty:

[root@vps public_html]# java -jar SpringBootProject-0.0.1-SNAPSHOT.jar -bash: java: command not found [root@vps public_html]#

How do I fix this?

Learner
  • 123
  • 1
  • 13
  • Relevant reading: https://stackoverflow.com/questions/10382929/how-to-fix-java-lang-unsupportedclassversionerror-unsupported-major-minor-versi also the problem you got after fixing the version mismatch is probably better asked as a new question, but it sounds like Java 8 is not configured properly on the system. What happens when you use `java -version` in the SSH console after removing Java 7? Does it correctly recognise `java` as a valid command? – sorifiend Oct 08 '21 at 03:19
  • I checked it and what I get is: -bash: java: command not found . I re-installed java 7 in vps server and when I check the java version I get: 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) – Learner Oct 08 '21 at 03:54
  • It looks like even though the VPS server indicates that java 8 is installed it is not recognized in ssh terminal. – Learner Oct 08 '21 at 03:55
  • Excellent, that is an easy problem to solve. You can run the application using the full path to the java 8 directory, or you need to make the VPS aware of where java 8 is located (adding it to the class path). This will vary by the system, but there is plenty of information online about how to do this. – sorifiend Oct 08 '21 at 03:58
  • I was able to install java 8 successfully in the vps server and also set java version 8 in my POM file and in the build path I added the correct JRE for java 8 and I no longer get this error message. It worked. – Learner Oct 09 '21 at 03:54

0 Answers0