1

I'm using Windows 10, JDK 10.0.1.

I'm trying to compile a program using the command line but whenever I try to specify javac it does not work. It will say one of two messages depending on the method.

Method 1 Using the JAVA_HOME method, I'll type javac Example.java in the command line and it will say:

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

Path Setup for Method #1: https://gyazo.com/3503ef29c48175385768d8cd9b068ce4

Method 2 Using the direct Java bin path method:

C:\Program Files\Java\jdk-10.0.1\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;

The output will be:

javac: file not found: Example.java
Usage: javac <options> <source files>
use --help for a list of possible options

Path Setup for Method #2: In the Environment Variables -> System variables I've tried to add the Java bin path to the "Path" variable. I tried adding "C:\Program Files\Java\jdk-10.0.1\bin" at the front and end of the path like so:

  1. Front: https://gyazo.com/22d4e4ac35a34af5d1333b74e7c16c88
  2. End: https://gyazo.com/f066abbd45a5f16f4c49232890263299

Sources:

  1. javac is not recognized as an internal or external command, operable program or batch file
  2. javac: file not found: first.java Usage: javac <options> <source files>
halfer
  • 19,824
  • 17
  • 99
  • 186
Tom W.
  • 45
  • 1
  • 8
  • Possible duplicate of [How do I run a Java program from the command line on Windows?](https://stackoverflow.com/questions/16137713/how-do-i-run-a-java-program-from-the-command-line-on-windows) – halfer Jun 20 '18 at 17:48
  • Please do not add meta-commentary ('reopened') or pleading ('help please') to titles. – halfer Jun 22 '18 at 07:59
  • Sorry, didn't realize it was against the rules to ask for help politely (using please). Not trying to sound like a smart-ass by the way, I am being sincere. As for re-opened I added that because anyone who had seen I put "Solved" earlier would assume it's closed, but it's not and I still needed help. Good to know though, will not do again. As for the duplicate, it does not appear to be. My issue is different than theirs from what I read. – Tom W. Jun 23 '18 at 02:50
  • It's not so much as a hard-and-fast rule as it is a guideline about clarity; people who add chatty material to their posts, as if Stack Overflow was a forum, have not transgressed in a terrible way. Rather, we hope that [writers will notice the edits to their questions](https://stackoverflow.com/posts/50953386/revisions) and start writing in a more succinct fashion naturally. I commented in this case because I had to make an edit twice (in retrospect I suspect you just did not notice the first one, so overwrote it). – halfer Jun 23 '18 at 09:34
  • The reference discussion [is here](https://meta.stackoverflow.com/q/260776/472495) and [this editing discussion](https://meta.stackoverflow.com/q/288160/472495) is in a similar vein. I wondered if this was a duplicate because, at its root, the problem is a Windows `PATH` not being correctly set for the binary you want, and that has been covered hundreds of time on this site. – halfer Jun 23 '18 at 09:36
  • Ah okay, good to know. Do I have to type "path JAVA_HOME\bin;%path%" each time I want to compile something by the way? Because that would explain why it didn't seem to work each restart. – Tom W. Jun 29 '18 at 04:07

1 Answers1

1

As you can see in your environment settings you have JAVA_HOME:

C:\Program Files\Java\jdk-10.0.1\bin

And in path variable you do this:

%JAVA_HOME%\bin

So your path looks like:

C:\Program Files\Java\jdk-10.0.1\bin\bin

Which doesn't exist.

Second thing is that JAVA_HOME should point to jdk catalog not bin

Solution:

Change your JAVA_HOME to this:

C:\Program Files\Java\jdk-10.0.1
Rafał Sokalski
  • 1,817
  • 2
  • 17
  • 29
  • Oh okay. Now my JAVA_HOME is: C:\Program Files\Java\jdk-10.0.1 and my PATH is: https://gyazo.com/d67706bf8bd40de8887d699c5b164671 But it still doesn't work – Tom W. Jun 20 '18 at 17:19
  • You changed it in path which is incorrect. Change variable JAVA_HOME without bin and in path variable leave %JAVA_HOME%\bin – Rafał Sokalski Jun 20 '18 at 17:22
  • Ohh okay. Now it half works unless I'm misunderstanding it. When I first open the cmd can I just type "javac Example.java" and it will find it on the pc? Or am I supposed to enter the path of the file first such as using "cd Desktop\JAVA\Example" then "javac Example.java"? If I just do "javac Example.java" it doesn't work but if I specify the path first then it does. – Tom W. Jun 20 '18 at 17:29
  • You have to be inside directory where is your Example.java file – Rafał Sokalski Jun 20 '18 at 17:32
  • More information [here](https://stackoverflow.com/questions/16137713/how-do-i-run-a-java-program-from-the-command-line-on-windows) – Rafał Sokalski Jun 20 '18 at 17:34
  • @PiggiesGoSqueal accept my answer if it helped you, please. – Rafał Sokalski Jun 20 '18 at 19:13
  • Done, sorry about that. Didn't realize there was another option other than upvoting which I can't really do because I'm new. – Tom W. Jun 21 '18 at 01:44
  • Sokalski Well.. today I'm having the same issue. Pic: https://gyazo.com/affb80b47fdfcb70944adce3a381d72b Only change between then and now is that I turned off and on my laptop. How can I set up PATH so it works even after system restarts? PATH Info: https://gyazo.com/7a248a44c21d832795f846c5d3cf7905 – Tom W. Jun 21 '18 at 20:38
  • That is correct @Rafal Sokalski. I had to go through the steps again to get it to work again. I'd rather not have to do that every single day after a restart. Any idea what could be causing this issue? Thanks – Tom W. Jun 23 '18 at 02:42