Linux Mint下JDK1.8.0_162启动报错java/lang/NoClassDefFoundError求助
Hey there, let's work through this JDK issue together — that java/lang/NoClassDefFoundError: java/lang/Object error typically means your system can't properly access the core JDK libraries, or there's a problem with your environment setup. Here's how to fix it step by step:
1. Verify Your JDK Installation is Complete
First, check if the core JDK library file exists — this is where java/lang/Object lives. Run this command:
ls -l /opt/java/jdk1.8.0_162/jre/lib/rt.jar
If the output says the file doesn't exist, your JDK installation is corrupted. You'll need to redownload the JDK 1.8.0_162 archive, delete the current /opt/java/jdk1.8.0_162 directory, and re-extract the new archive to /opt/java.
2. Fix Your Environment Variable Configuration
Your current PATH setup might be missing the critical JAVA_HOME variable, and the order of PATH entries could be causing issues. Open your .bashrc file with a text editor (like nano):
nano ~/.bashrc
Replace your existing JDK line with these two lines:
export JAVA_HOME=/opt/java/jdk1.8.0_162 export PATH=$JAVA_HOME/bin:$PATH
Adding JAVA_HOME ensures tools that depend on it work correctly, and putting $JAVA_HOME/bin at the start of PATH makes sure your installed JDK is prioritized over any system-wide Java versions.
3. Reload the Environment Variables
Save the .bashrc file (in nano, press Ctrl+O then Enter, then Ctrl+X to exit), then reload the changes with:
source ~/.bashrc
Verify the variables are set correctly:
echo $JAVA_HOMEshould output/opt/java/jdk1.8.0_162echo $PATHshould show/opt/java/jdk1.8.0_162/binnear the beginningwhich javashould return/opt/java/jdk1.8.0_162/bin/java
4. Check Directory Permissions
If your user doesn't have proper access to the JDK files, that can cause library loading errors. Fix the permissions with:
sudo chown -R $USER:$USER /opt/java/jdk1.8.0_162
This recursively sets ownership of the JDK directory to your current user, ensuring you can read and execute all files.
5. Test the Java Command
Finally, run java -version to see if the error is resolved. If it still occurs, double-check that you downloaded the correct JDK for your system architecture (32-bit vs 64-bit) — mismatched architecture can also cause this kind of initialization error.
内容的提问来源于stack exchange,提问作者Bipul Roy

