0
votes

i created a docker container for a simple java application .

creation of Docker image is correctely done . when i run docker run i have some problem related to java , but the application work well when i run it using IntelliJ.

docker Errors :

PS C:\Windows\system32> docker run testing Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/JMSException at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) at java.lang.Class.privateGetMethodRecursive(Class.java:3048) at java.lang.Class.getMethod0(Class.java:3018) at java.lang.Class.getMethod(Class.java:1784) at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526) Caused by: java.lang.ClassNotFoundException: javax.jms.JMSException at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 7 more

Dockerfile:

FROM openjdk:8-jre
COPY /target/application.jar /tmp/application.jar
WORKDIR /tmp
ENTRYPOINT ["java", "-cp", "application.jar", "Package.ClassWithMain"]

Thank you in advance, Mondher

2
Forget about docker first. Can you try running your jar on your command line, without Intellij. I have a doubt on how you have created your jar file. It might not have all runtime/dependencies required. - Gorav Singal

2 Answers

1
votes

You: COPY /target/application.jar /tmp/application.jar Try: COPY . /usr/src/myapp

You: WORKDIR /tmp Try: WORKDIR /usr/src/myapp

Look for its written, should help!

RUN javac Main.java CMD ["java", "Main"]

0
votes

The issue could be that your jar is lacking certain dependencies. Intellij may have the required dependencies in the build path which is why your application runs from that environment. Are you using maven or a build tool to create the jar?