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
Similar Posts:
- [Solved] Err:12 http://security.ubuntu.com/ubuntu focal-updates/main amd64 openjdk-11-jre-headless amd64 11.0.11+9-0ubuntu2~20.04 404 Not Found [IP: 91.189.88.152 80]
- Linux Run javac Error: javac: command not found
- Error: JAVA_HOME is not set [How to Solve]
- [Solved] JAVA Run Error: Error: Could not find or load main class
- gradle –version Error: ERROR: JAVA_HOME is set to an invalid directory: /usr/local/opt/openjdk
- [Solved] java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/ImageFormatException (Upload Images Error)
- [Solved] NB: JAVA_HOME should point to a JDK not a JRE
- [Solved] E: dpkg was interrupted, you must manually run ‘dpkg –configure -a’ to correct the probl…
- [Java] deepin solves the problem of picked up in JDK_JAVA_Options:-AWT. Usesystemaafontsettings=gasp
- The CATALINA_HOME environment variable is not defined correctly