简体   繁体   中英

'javac' is not recognized . .

I want to compile my programs I made in VS Code but I cannot because allegedly

'javac' is not recognized as an internal or external command, operable program or batch file.

Doing some searching around, I feel like as though it should be working:

  1. With all the necessary extensions, I have set the java.home in the user settings in VS Code to override environment variables:

"java.home":"C:\\\\Program Files\\\\Java\\\\jdk1.8.0_181\\\\bin"

That one didn't work, but I also tried it without "\\\\bin" too and there was no luck to that, either.

  1. I tried setting the JAVA_HOME and JDK_HOME to the same path listed above and attempted including the \\bin and not. Both did not work
  2. the JDK/Javac does not appear when I execute "where java" or "java -version" within the command prompt (I run on Windows 8.1)

I used the command prompt to navigate to the javac file, and alas that is the only known method that works. (However, javac does not work if I change my directory elsewhere.) What do I do? Why is this happening?

JAVA_HOME should point to the path where your JDK is installed. This is: C:\\Program Files\\Java\\jdk1.8.0_181. After that, you should edit your PATH environment variable to add the following entry.

Windows:

PATH=%JAVA_HOME%\bin;<rest of current PATH value>

*-nix systems (Linux, Mac):

export PATH=$JAVA_HOME/bin:$PATH

A rough explanation for PATH: is the system environment variable in charge of making executables available through command line. This is why its value needs to contain the bin folder inside JAVA_HOME , and JAVA_HOME value is the path (you may update it to point to a different JDK).

After updating the value of PATH, you may open a terminal (cmd in Windows) and type:

javac -version

You should see an output like this:

javac 1.8.0_181

And now javac will be available for any application to use it eg VS Code.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM