0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

Thank you. It appeared that an older version of java.exe was installed at part of the Windows OS and reflected in the PATH system variable before the JAVA_HOME\bin
You probably have installed it in a browser way back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.