Anthony
Anthony

Reputation: 195

Exception in thread "main" java.lang.UnsupportedClassVersionError:

I am using JDK 14 on Netbeans on Windows 10. Everything works fine in the IDE environment. However, when I try to compile and run a source file from the command prompt, I get the java.lang.UnsupportedClassVersionError.

JAVA_HOME=c:\java\jdk14

The PATH and CLASSPATH in the system variables contain JAVA_HOME\bin, JAVA_HOME\lib.

If I issue java -version from the command prompt, in the JAVA_HOME directory, I get the following:

java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) Client VM (build 25.251-b08, mixed mode)

If I issue java -version from the JAVA_HOME\bin directory I get a different message listed below:

java version "14.0.1" 2020-04-14
Java(TM) SE Runtime Environment (build 14.0.1+7)
Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)

I am not sure why? Please offer any advice. Thanks

Upvotes: 0

Views: 713

Answers (2)

The thing that determines which version of Java is being run is which java.exe file is being run, which from the command line is solely determined by the %PATH% variable.

JAVA_HOME and JDK_HOME are typically used by wrappers that need to find the Java command on disk. If you point directly to the java.exe file, they are not needed. I would suggest prepending C:\java\jdk14 to your PATH environment variable.

Upvotes: 0

Christian Frommeyer
Christian Frommeyer

Reputation: 1420

Sounds like you have the path to a java binary of version 8 in the PATH as well and before the JAVA_HOME entries. You should be able to find out which java is used with the where command like where java. Or just put the JAVA_HOME entries at the very beginning of the PATH variable.

Upvotes: 1

Related Questions