0

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?

  • Possible duplicate of [javac not working in windows command prompt](https://stackoverflow.com/questions/1678520/javac-not-working-in-windows-command-prompt) – user3486184 Aug 29 '18 at 21:18
  • VSCode for Java? It's far simper to use something java specialized like IntelliJ, Eclipse, ... and you get a *lot* more smart contextual help. But if you want to, the `JAVA_HOME` variable is without the `/bin` directory. And/Or you could put the path in PATH (this time including `bin`) so the `javac` executable can be found. Btw, have you checked that the path is actually the correct one? – zapl Aug 29 '18 at 21:23

1 Answers1

0

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 e.g. VS Code.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332