【问题标题】:cf push failed java version mismatchcf push 失败 java 版本不匹配
【发布时间】:2020-10-20 22:13:52
【问题描述】:

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

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)

【问题讨论】:

    标签: java spring exception push cloud-foundry


    【解决方案1】:

    注意这一点:

    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
    

    你已经用Java 11的编译器编译了你的项目,它会得到你的字节码版本55.0

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

    您可以cross-compile您的项目以支持较旧的 Java 版本。请参阅here 如何做到这一点。

    【讨论】:

      【解决方案2】:

      虽然Giorgi's answer 也是正确的,但您可能想要做的只是使用 Java 11 来运行您的应用程序。

      您可以告诉 Java buildpack 您希望安装 Java 11,而不是默认的(我写这篇文章时)Java 8。

      对您的应用运行cf set-env <app-name> JBP_CONFIG_OPEN_JDK_JRE '{jre: { version: 11.+ }}' 或将该环境变量添加到您的 manifest.yml 中。然后cf restage你的应用程序。 Java buildpack 会看到它并自动为您安装 Java 11。

      【讨论】:

      • 谢谢丹尼尔。我取消了 spring-music 文件夹中 manifest.yml 中的 env 变量的注释。之后,我运行“cf restage spring-music”命令,然后它就起作用了。
      猜你喜欢
      • 2021-09-21
      • 2015-02-28
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-28
      • 2019-02-21
      相关资源
      最近更新 更多