I am using OpenJDK 11 on Debian. Whenever I try to run java -version
, I get this:
Error: Could not find or load main class
Caused by: java.lang.ClassNotFoundException:
However, running like this works:
/usr/lib/jvm/java-11-openjdk-amd64/bin/java -version
I checked the symlinks, they all worked fine. If javac
can work, why can't java
, because both of them are in the same folder. What am I missing?
I get the same when trying to run any compiled classes. I recently tried (but failed) switching to a different JDK, before which I didn't have this problem. My $PATH and $JAVA_HOME are set correctly.
I finally found the answer. I took a step back, and thought out the exact steps I took when I changed my default JDK. When I had switched to 13, running java would echo a bunch of init settings on my screen, so I followed somebody's answer to suppress it, and THAT caused the error.
I had added this line to my.bash_profile to suppress it, and commenting it out followed by a reboot just solved the problem!
_SILENT_JAVA_OPTIONS="$_JAVA_OPTIONS" && unset _JAVA_OPTIONS && alias java='java "$_SILENT_JAVA_OPTIONS"'
PRO-TIP: If you're getting such errors, simply check which Environment variables could you have messed up with.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.