-3

So, I followed this example/tutorial in order to build a .jar file in Kubuntu 20.04.1 LTS: https://www.tecmint.com/create-and-execute-jar-file-in-linux/

I successfully run the .jar file on Kubuntu. Then I make a Dockerfile with these commands:

FROM java:8-jdk-alpine
WORKDIR /home/UbuntuUser/Desktop/docker/test_jar/
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "tecmintapp.jar"]

by modifying this tutorial:

Run jar file in docker image

I build the docker image with this command:

sudo docker build -t test-docker .

It builds successfully and then try to run it with this command:

UbuntuUser@ubuntu:~/Desktop/docker/test_jar/$ sudo docker run test-docker
Error: Unable to access jarfile tecmintapp.jar

Inside the "test_jar" folder I have these files:

TecmintApp.java
tecmintapp.jar
TecmintApp.class
MANIFEST.MF
Dockerfile

Maybe I miss something here, but do you see something wrong to all these? Why does the docker not run?

Update: @Hussain Bohra & @Zeitounator: I have done what you suggest, I built it correctly, but when try to run it I get this error:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: TecmintApp has been compiled by a more recent version of the Java Runtime (class file version 58.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:467)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)

I did a check and this is the feedback I get, I do not see difference in the editions of the packages:

$ java -version  
openjdk version "14.0.2" 2020-07-14
OpenJDK Runtime Environment (build 14.0.2+12-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 14.0.2+12-Ubuntu-120.04, mixed mode, sharing)

$ javac -version
javac 14.0.2
just_learning
  • 413
  • 2
  • 11
  • 24
  • 4
    You need to copy the jar from local machine into container. Like "COPY tecmintapp.jar /home/UbuntuUser/Desktop/docker/test_jar/tecmintapp.jar" – Hussain Bohra Mar 26 '21 at 21:28
  • 1
    `/home/UbuntuUser/Desktop/docker/test_jar/` is a directory on your local machine. It does not exists inside your image/container and its contents are not accessible from the running container. As reported above, you need to copy the file in your image. A quick fix to get you on track: remove the `WORKDIR ....` line, replace it with `COPY tecmintapp.jar .`. Then build the image again and (try to) run it. You might want to spend some more time getting the docker key concepts. A good starting point IMO: https://docs.docker.com/get-started/ – Zeitounator Mar 26 '21 at 23:07
  • I have updated the first post... Any ideas how to fix it?? – just_learning Mar 27 '21 at 12:46

1 Answers1

0

Solution: It needs FROM openjdk:14-alpine inside the Dockerfile

just_learning
  • 413
  • 2
  • 11
  • 24