使用java命令出现Error: A JNI error has occurred, please check your installation and try again的错误

Posted CircleYuan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用java命令出现Error: A JNI error has occurred, please check your installation and try again的错误相关的知识,希望对你有一定的参考价值。

运行Java程序,javac运行.java文件没有报错,但java运行的时候报错

?技术图片技术图片??

仔细看一下报错

Exception in thread "main" java.lang.UnsupportedClassVersionError: helloworld has been compiled by a more recent version of the Java Runtime (class file version 54.0), this version of the Java Runtime only recognizes class file versions up to 52.0

查一下原因,发现为java与javac版本不一致而造成的。

java -version和javac - version一下,果真如此

两个版本不一致

解决:

1、查询Linux系统内有多少java版本

rpm -qa |grep java

?技术图片技术图片??

2.然后一个个删除干净

rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.181-3.b13.el7_5.x86_64
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.171-2.6.13.0.el7_4.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.0.el7_4.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64 
(输入rpm -e --nodeps +“存在的java版本”)有多少删除多少

3、检验原有的java版本是否全部移除

[[email protected] 8-1]# java - version
-bash: /usr/bin/java: No such file or directory

4、原有的版本移除后配置新安装的java环境变量

vi /etc/profile 

编辑profile文件,在最后加上

JAVA_HOME=/usr/local/java/jdk-10.0.2/   ###(“jdk-10.0.2”改为你要安装的java版本的安装文件名)
JRE_HOME=$JAVA_HOME/           ###(由于jdk10解压缩后没有jre文件夹,如果为jdk10以下的版本应
                               为“JRE_HOME=$JAVA_HOME/jre”)
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
export JAVA_HOME JRE_HOME PATH CLASSPATH

5、最后更新一下

source /etc/profile

完成

?技术图片技术图片??

搬迁自我的CSDN博客:https://blog.csdn.net/kingyuan666

以上是关于使用java命令出现Error: A JNI error has occurred, please check your installation and try again的错误的主要内容,如果未能解决你的问题,请参考以下文章

Error: A JNI error has occurred, please check your installation and try again的全面解决方法

Error: A JNI error has occurred, please check your installation and try again

java A JNI error has occurred, please check your installation and try again A JNI error has occurr

Error: A JNI error has occurred, please check your installation and try again

Error: A JNI error has occurred, please check your installation and try again

Error: A JNI error has occurred, please check your installation and try again