Run Java program, javac run. Java file does not report an error, but when Java runs, it reports an error
Look at the error report carefully
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
Check the reason and find that it is caused by the inconsistency between Java and javac versions
Java – version and javac – version, if so
The two versions are inconsistent
Solution:
1. How many Java versions are there in Linux system
rpm -qa |grep java
2. Then delete them one by one
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
(type rpm -e --nodeps + "existing java version") Delete as many as you can
3. Check whether the original java version is removed completely
[root@yuan 8-1]# java - version
-bash: /usr/bin/java: No such file or directory
4. After the original version is removed, configure the newly installed Java environment variables
vi /etc/profile
Edit the profile file and add
JAVA_HOME=/usr/local/java/jdk-10.0.2/ ###("jdk-10.0.2" to the installation file name of the version of java you want to install)
JRE_HOME=$JAVA_HOME/ ### (since there is no jre folder after jdk10 is unzipped, if it is for a version below jdk10 it should
for “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. Last update
source /etc/profile
Complete