Java app fails to start on VMware Tanzu Application Service (TAS) due to mismatched JRE version.
After deploying a Java app to TAS, the app fails to start due to the error below:
2021-02-19T10:40:52.80+0000 [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
This is caused by a mismatched JRE version (with which the app is executed in container) and JDK version (with which the app is compiled). The Java buildpack in TAS supports multiple versions of JRE but the default is v8. In the above error message, 52.0 and 55.0 are the major and minor version numbers and are stored in the class bytecode at bytes six and seven. The major version numbers map to the Java versions below:
Thus the error message indicates that the app is compiled with JDK v11 and fails to start with JRE v8. To specify JRE version properly, please refer to Java buildpack repository, configure JBP_CONFIG_OPEN_JDK_JRE in deployment manifest as:
env: JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }'
Or in the environment variable as:
cf set-env YOUR_APP JBP_CONFIG_OPEN_JDK_JRE '{ jre: { version: 11.+ }}'