0

I'm trying to run a jar in a docker container but it fails with compilation issue.
My pom is like that :

    <maven.compiler.source>17</maven.compiler.source>
    <maven.compiler.target>17</maven.compiler.target>

The Dockerfile starts as follow :

FROM openjdk:17-ea-17-jdk-oracle

The java -version is locally (and so used to compile) :

openjdk version "17.0.7" 2023-04-18
OpenJDK Runtime Environment (build 17.0.7+7-Ubuntu-0ubuntu122.04.2)
OpenJDK 64-Bit Server VM (build 17.0.7+7-Ubuntu-0ubuntu122.04.2, mixed mode, sharing)

And when I try to run the container, it fails with the following message in the logs :

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class: URL [jar:file:***-8.0.0-SNAPSHOT.jar!package/MyClass.class]; nested exception is org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: URL [jar:file:***8.0.0-SNAPSHOT.jar!package/MyClass.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
2023-07-11T09:36:30.792324136Z  at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:454)
2023-07-11T09:36:30.792330112Z  at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.findCandidateComponents(ClassPathScanningCandidateComponentProvider.java:316)
2023-07-11T09:36:30.792334795Z  at org.springframework.context.annotation.ClassPathBeanDefinitionScanner.doScan(ClassPathBeanDefinitionScanner.java:275)
2023-07-11T09:36:30.792338818Z  at org.springframework.context.annotation.ComponentScanAnnotationParser.parse(ComponentScanAnnotationParser.java:132)
2023-07-11T09:36:30.792342490Z  at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:287)
2023-07-11T09:36:30.792346526Z  at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:242)
2023-07-11T09:36:30.792350611Z  at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:199)
2023-07-11T09:36:30.792354840Z  at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
2023-07-11T09:36:30.792358458Z  at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:315)
2023-07-11T09:36:30.792364075Z  at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:232)
2023-07-11T09:36:30.792368200Z  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:275)
2023-07-11T09:36:30.792371846Z  at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:95)
2023-07-11T09:36:30.792390554Z  at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:705)
2023-07-11T09:36:30.792397705Z  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
2023-07-11T09:36:30.792451118Z  at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
2023-07-11T09:36:30.792468006Z  at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
2023-07-11T09:36:30.792472375Z  at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
2023-07-11T09:36:30.792475985Z  at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
2023-07-11T09:36:30.792479268Z  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
2023-07-11T09:36:30.792482622Z  at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
2023-07-11T09:36:30.792485898Z  at package.Main.main(Main.java:23)
2023-07-11T09:36:30.792489480Z  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2023-07-11T09:36:30.792493042Z  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
2023-07-11T09:36:30.792496403Z  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2023-07-11T09:36:30.792499785Z  at java.base/java.lang.reflect.Method.invoke(Method.java:568)
2023-07-11T09:36:30.792503366Z  at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
2023-07-11T09:36:30.792509219Z Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: URL [jar:file:***-8.0.0-SNAPSHOT.jar!package/MyClass.class]; nested exception is java.lang.IllegalArgumentException: Unsupported class file major version 61
2023-07-11T09:36:30.792513634Z  at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:57)
2023-07-11T09:36:30.792517334Z  at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:103)
2023-07-11T09:36:30.792520942Z  at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:123)
2023-07-11T09:36:30.792524564Z  at org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider.scanCandidateComponents(ClassPathScanningCandidateComponentProvider.java:430)
2023-07-11T09:36:30.792528064Z  ... 25 common frames omitted
2023-07-11T09:36:30.792531292Z Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 61
2023-07-11T09:36:30.792534698Z  at org.springframework.asm.ClassReader.<init>(ClassReader.java:184)
2023-07-11T09:36:30.792546986Z  at org.springframework.asm.ClassReader.<init>(ClassReader.java:166)
2023-07-11T09:36:30.792550659Z  at org.springframework.asm.ClassReader.<init>(ClassReader.java:152)
2023-07-11T09:36:30.792554423Z  at org.springframework.asm.ClassReader.<init>(ClassReader.java:273)
2023-07-11T09:36:30.792558037Z  at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:54)
2023-07-11T09:36:30.792561610Z  ... 28 common frames omitted

If I try a java -version, it also is java 17

BenjaminD
  • 488
  • 3
  • 13
  • Was that jar compiled with Java 17? Likely a version conflict… indicated by `Unsupported class file major version 61` – deHaar Jul 11 '23 at 09:47
  • The manifest of the jar says Build-Jdk: 17.0.7. I get the version conflict but I don't understand where it comes from : everything is in 17 – BenjaminD Jul 11 '23 at 09:50
  • Looks like in your container is an older java version installed – Jens Jul 11 '23 at 09:51
  • Java version in the container is : openjdk version "17-ea" 2021-09-14 OpenJDK Runtime Environment (build 17-ea+17-1401) OpenJDK 64-Bit Server VM (build 17-ea+17-1401, mixed mode, sharing) So same Major version – BenjaminD Jul 11 '23 at 09:54
  • we don't see the value of `${version.java}` – mangusta Jul 11 '23 at 09:58
  • 5
    1. OpenJDK doesn't do updated releases, so you should never use one in production. 2. The `-ea-` suggests that this is an Early Access build of the JDK, you should **definitely** never use that one in production. To fix 1 and 2, switch to a supported JDK (like Temurin). 3. The problem comes from the `ASM ClassReader failed to parse class file` which means its not the JDK itself complaining, but ASM. That means that the Spring version you use doesn't support running with code compiled against Java 17. Make sure to update to at least the latest minor version of Spring. Spring Boot >= 2.5. – Joachim Sauer Jul 11 '23 at 09:59
  • ${version.java} fixed and replaced by the variable value – BenjaminD Jul 11 '23 at 10:11

0 Answers0