[英]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:我正在尝试在服务器上执行 jar ,如下所示: java -jar file.jar
但我收到以下错误:
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.我知道这似乎与我的 jar 文件使用 Java 11 的事实有关,而服务器仅安装了 Java 8。 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.我无法安装 Java 11,正如人们在其他处理此问题的帖子上所建议的那样,因为我在我不是超级用户的服务器上执行。 I also would like to avoid reprogramming my whole project with Java 8.我还想避免使用 Java 8 重新编程我的整个项目。
Is there a way for me to execute my jar file anyways?有没有办法让我执行我的 jar 文件?
If you have access to the source code of file.jar
, you could try and create a jar for java 8 from it.如果您可以访问file.jar
的源代码,您可以尝试从中为 java 8 创建一个 jar。 If it fails, then there are some newer features used.如果失败,则使用了一些较新的功能。 You can go through the code and manually downgrade it.您可以通过代码 go 手动降级。
Another option would be to ship a local installation (no superuser rights required) of java with the software.另一种选择是随软件一起提供 java 的本地安装(无需超级用户权限)。
As commented, multiple solutions exist.正如所评论的,存在多种解决方案。 I found the easiest were the following two solutions:我发现最简单的是以下两种解决方案:
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:.
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
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
我最终要求超级用户安装 Java 11,他们告诉我已经安装在someFolder/java11/bin/java
,所以我最终使用someFolder/java11/bin/java -jar file.jar
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.