2

I'm trying to push "spring-music" demo application to my local dev cloud foundary, but I'm getting below error. When I run the command "cf logs spring-music --recent" I got the output below.

2020-10-21T00:41:39.96+0300 [APP/PROC/WEB/0] OUT JVM Memory Configuration: -Xmx408076K -Xss1M -XX:ReservedCodeCacheSize=240M -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=128499K
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR Exception in thread "main" java.lang.UnsupportedClassVersionError: org/cloudfoundry/samples/music/Application has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0                                                                                                                                                                                                                   
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.lang.ClassLoader.defineClass1(Native Method)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.security.AccessController.doPrivileged(Native Method)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
   2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR     at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)

2 Answers2

5

While Giorgi's answer is also correct, what you probably want to do is just use Java 11 to run your app.

You can tell the Java buildpack that you'd like to have Java 11 installed instead of the default (as I write this), which is Java 8.

Run cf set-env <app-name> JBP_CONFIG_OPEN_JDK_JRE '{jre: { version: 11.+ }}' against your app or add that env variable into your manifest.yml. Then cf restage your app. The Java buildpack will see it and automatically install Java 11 for you.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • Thanks Daniel. I uncommented the env variable in manifest.yml in spring-music folder. After that, I ran "cf restage spring-music" command then it worked. – Yasin Ünal Oct 22 '20 at 21:58
4

Pay attention to this:

Application has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

You have compiled your project with Java 11's compiler, which gets you bytecode version 55.0;

Your host machine is running Java 8, which runs bytecode version 52.0.

You can cross-compile your project to support older Java versions. See here how to do that.

Giorgi Tsiklauri
  • 9,715
  • 8
  • 45
  • 66