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>
6
  • Possible duplicate of How do I run a Java program from the command line on Windows? Commented Jun 20, 2018 at 17:48
  • Please do not add meta-commentary ('reopened') or pleading ('help please') to titles. Commented Jun 22, 2018 at 7: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. Commented Jun 23, 2018 at 2: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 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). Commented Jun 23, 2018 at 9:34
  • The reference discussion is here and this editing discussion 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. Commented Jun 23, 2018 at 9:36

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

9 Comments

Oh okay. Now my JAVA_HOME is: C:\Program Files\Java\jdk-10.0.1 and my PATH is: gyazo.com/d67706bf8bd40de8887d699c5b164671 But it still doesn't work
You changed it in path which is incorrect. Change variable JAVA_HOME without bin and in path variable leave %JAVA_HOME%\bin
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.
You have to be inside directory where is your Example.java file
More information here
|

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.