0

I was able to dock my project in Spring Boot from the following docker file:

FROM openjdk:7-jdk-alpine
ARG JAR_FILE=target/edms-influx-device-fixer-1.2.1.jar
COPY ${JAR_FILE} edms-influx-device-fixer-1.2.1.jar
ENTRYPOINT ["java","-jar","edms-influx-device-fixer-1.2.1.jar"]

But when I try to run with the docker command: docker run -p 8085: 8085 name project

Take this exception:

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/JarLauncher : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:808)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:443)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:65)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:349)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:348)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:430)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:323)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

I state that my JAVA_HOME environment variable points to jdk-14.0.2

If in my docker file I use: openjdk:8-jdk-alpine I get this exception:

Exception in thread "main" java.lang.UnsupportedClassVersionError: com/xxxx/xxxx/xxxx/App 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

How Can I solve this exception?

guidop21
  • 177
  • 3
  • 15
  • 2
    Use `FROM openjdk:14-jdk-alpine` instead of `FROM openjdk:7-jdk-alpine`, since you are using java 14 locally. Making sure the enviomets match is the first step – Ferrybig Jun 03 '21 at 13:58

1 Answers1

3

Unsupported major.minor version 52.0 means your code/libaries you are using, was compiled with Java 8. and you are trying to run on Java 7 FROM openjdk:7-jdk-alpine so it will not work.

The solution is to switch to running on Java 8+ e.g. FROM openjdk:8-jdk-alpine. Or to change your code/dependencies to be Java 7 compatible.

James Mudd
  • 1,816
  • 1
  • 20
  • 25