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:
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