Reputation: 448
I've started working on a microservice project. So the docker image of my service was compiled in Jdk11. When I try to download and run the container - it doesn't run. Now upon checking logs, I see - java.lang.UnsupportedClassVersionError I'm using maven to build. Should I change the java version in pom.xml? I could not update the java version in the ec2. Please let me know how I can resolve this collision and go-ahead. I have many services and I'm trying to put it all in EC2.
Docker file: updated to Java 11
FROM openjdk:11.0-jdk-slim
VOLUME /tmp
COPY snapAppKey.jks snapAppKey.jks
COPY /target/SnapAppConfigServer-0.0.1-SNAPSHOT.jar ConfigServer.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","ConfigServer.jar"]
EC2
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/snapapp/config/api/SnapAppConfigServerApplication 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
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Upvotes: 0
Views: 2091
Reputation: 4045
Migrating your existing code from JDK11 to JDK8 will be more effort that the above simple operations.
change openjdk:8-jdk-alpine
to openjdk:11
in your Docker file
Upvotes: 2