简体   繁体   中英

How to execute a Java 11 jar with only Java 8 installed?

I'm trying to execute a jar on a server, like so: java -jar file.jar but I get the following error:

A JNI error has occurred, please check your installation and try again 
... 
Class has been compiled by a more recent version of the Java Environment (class file version 55.0), 
this version of the Java Runtime only recognizes class file versions up to 52.0.

I understand this seems to relate to the fact that my jar file uses Java 11, while the server only has Java 8 installed. I cannot install Java 11 as people suggest on other posts treating this issue, since I'm executing on a server on which I am not super user. I also would like to avoid reprogramming my whole project with Java 8.

Is there a way for me to execute my jar file anyways?

If you have access to the source code of file.jar , you could try and create a jar for java 8 from it. If it fails, then there are some newer features used. You can go through the code and manually downgrade it.

Another option would be to ship a local installation (no superuser rights required) of java with the software.

As commented, multiple solutions exist. I found the easiest were the following two solutions:

  • Ask the server's super users to install Java 11.
  • Download jdk-11.0.11_linux-x64_bin.tar.gz from https://www.oracle.com/java/technologies/javase-jdk11-downloads.html , which can be copied onto the server with scp jdk-11.0.11_linux-x64_bin.tar.gz serverName:. Unpack with tar xvzf jdk-11.0.11_linux-x64_bin.tar.gz on the server and then execute your jar file with jdk-11.0.11_linux-x64_bin.bin.java -jar file.jar

I ended up asking the super users to install Java 11, which they told me was already installed at someFolder/java11/bin/java , so I ended up using someFolder/java11/bin/java -jar file.jar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM