cf推送失败,Java版本不匹配。

huangapple go评论79阅读模式
英文:

cf push failed java version mismatch

问题

我正在尝试将“spring-music”演示应用程序推送到我的本地开发Cloud Foundry,但是我遇到了以下错误。当我运行命令“cf logs spring-music --recent”时,我得到了以下输出。

2020-10-21T00:41:39.96+0300 [APP/PROC/WEB/0] OUT JVM内存配置:-Xmx408076K -Xss1M -XX:ReservedCodeCacheSize=240M -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=128499K
2020-10-21T00:41:40.64+0300 [APP/PROC/WEB/0] ERR 在线程“main”中的异常 java.lang.UnsupportedClassVersionError:org/cloudfoundry/samples/music/Application已由更高版本的Java Runtime(类文件版本55.0)编译,此版本的Java Runtime仅识别高达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)
英文:

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)

答案1

得分: 5

虽然Giorgi的回答 也是正确的,但你可能想要做的就是使用Java 11来运行你的应用。

你可以告诉Java构建包,你想要安装的是Java 11,而不是默认的Java 8(在我撰写本文时)。

运行以下命令 cf set-env <app-name> JBP_CONFIG_OPEN_JDK_JRE '{jre: { version: 11.+ }}' 到你的应用,或者将该环境变量添加到你的 manifest.yml 文件中。然后执行 cf restage 你的应用。Java构建包会识别并自动为你安装Java 11。

英文:

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 &lt;app-name&gt; JBP_CONFIG_OPEN_JDK_JRE &#39;{jre: { version: 11.+ }}&#39; 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.

答案2

得分: 4

请注意以下内容:

应注意以下事项:
应用程序已由较新版本的Java运行时(类文件版本55.0)编译,此版本的Java运行时仅识别高达52.0的类文件版本。

您已使用Java 11的编译器编译了您的项目,这将生成字节码版本55.0;

您的主机计算机正在运行Java 8,它运行字节码版本52.0。

您可以[交叉编译](https://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/javac.html#crosscomp-options)您的项目以支持旧版Java版本。请参阅[此处](https://stackoverflow.com/a/11364910/1553537)了解如何进行操作。
英文:

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.

huangapple
  • 本文由 发表于 2020年10月21日 06:13:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/64454073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定