1

I have tried everything and looked all over this site for answers, but nothing worked. Any ideas? I googled and played with it, still nothing.

Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved.

C:\Users\sean>set path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin\javac.exe"

C:\Users\sean>cd Desktop

C:\Users\sean\Desktop>javac Welcome.java 'javac' is not recognized as an internal or external command, operable program or batch file.

C:\Users\sean\Desktop>java Welcome 'java' is not recognized as an internal or external command, operable program or batch file.

C:\Users\sean\Desktop>

Drolltv65
  • 13
  • 1
  • 2
  • 6
  • java isn't found in your PATH. – Alex Suo Jan 06 '17 at 07:42
  • the PATH environment setting should contain directories, not individual files. Try with `set path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin"` – Thomas Kläger Jan 06 '17 at 07:47
  • It's still not running the program. – Drolltv65 Jan 06 '17 at 08:11
  • Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\Users\sean>set path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin" C:\Users\sean>java Welcome Error: Could not find or load main class Welcome C:\Users\sean>java Welcome.java Error: Could not find or load main class Welcome.java C:\Users\sean> – Drolltv65 Jan 06 '17 at 08:11

4 Answers4

5

You should be adding Java's bin directory, not the executable, to the path, at least according to what my own setup is locally. Try using this:

setx path "%path%;C:\Program Files (x86)\Java\jdk1.8.0_111\bin"

But you should really update the path permanently from the Windows Control Panel.

If you want to circumvent all of this to run a Java process one time from the command line, you can also use the fully qualified path to javac.exe, e.g.

C:\Users\sean\Desktop> C:\Program Files (x86)\Java\jdk1.8.0_111\bin\javac.exe Welcome.java
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\Users\sean>set path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin\javac.exeWelcome" C:\Users\sean>"C:\Program Files (x86)\Java\jdk1.8.0_111\bin\javac.exeWelcome.java" '"C:\Program Files (x86)\Java\jdk1.8.0_111\bin\javac.exeWelcome.java"' is not recognized as an internal or external command, operable program or batch file. C:\Users\sean>set path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin\javac.exeWelcome.java" C:\Users\sean> – Drolltv65 Jan 06 '17 at 07:52
  • You're missing a space between `javac.exe` and `Welcome.java` ... can't you see that? But you should _really_ set the path from Control Panel, so you don't have to keep doing it this way. – Tim Biegeleisen Jan 06 '17 at 07:53
  • I have been at this for hours. I have done it with space and without space. How to set it from the control Panel? I think I have done that too. – Drolltv65 Jan 06 '17 at 07:56
  • Try `setx path ...` from the command line – Tim Biegeleisen Jan 06 '17 at 07:56
  • What did I do wrong? – Drolltv65 Jan 06 '17 at 08:03
  • Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\Users\sean>setx path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin\javac.exe Welcome.java" ERROR: Invalid syntax. Type "SETX /?" for usage. C:\Users\sean>setx path ERROR: Invalid syntax. Type "SETX /?" for usage. C:\Users\sean> – Drolltv65 Jan 06 '17 at 08:03
  • @Drolltv65 Sorry, you should just add the `bin` directory, not `javac.exe` – Tim Biegeleisen Jan 06 '17 at 08:04
  • Still not working – Drolltv65 Jan 06 '17 at 08:12
  • Microsoft Windows [Version 10.0.14393] (c) 2016 Microsoft Corporation. All rights reserved. C:\Users\sean>set path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin" C:\Users\sean>java Welcome Error: Could not find or load main class Welcome C:\Users\sean>java Welcome.java Error: Could not find or load main class Welcome.java C:\Users\sean> – Drolltv65 Jan 06 '17 at 08:12
  • When you run a Java program, you use `java Welcome`, _without_ the extension. Also, make sure that `Welcome.class` is present in `C:\Users\sean` by typing `dir` and checking for it. – Tim Biegeleisen Jan 06 '17 at 08:13
  • That helped. I don't see it in my dir. So now I have to firgure out how to get it in my dir. – Drolltv65 Jan 06 '17 at 08:17
  • This is my last comment here: Compile `Welcome.java`, which will generate `Welcome.class`, and then run `javac` from the location where that class file is. – Tim Biegeleisen Jan 06 '17 at 08:18
  • Thanks Tim. That worked! – Drolltv65 Jan 06 '17 at 08:23
  • 1
    @Drolltv65 Is upvote possible? – Tim Biegeleisen Jan 06 '17 at 08:26
2

Here is one mistake:

set path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin\javac.exe"

That should be

set path="C:\Program Files (x86)\Java\jdk1.8.0_111\bin"

(... assuming that "C:\Program Files (x86)\Java\jdk1.8.0_111" is the correct path for your JDK installation ...)

The PATH variable is supposed to be a search path comprising a directory, or list of directories separated by ';' characters. You cannot add a specific executable (file) to the search path.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

Oracle Java tutorials are a good starting point to go through when beginning to learn Java. Refer https://docs.oracle.com/javase/8/docs/technotes/guides/install/windows_jdk_install.html#BABGDJFH which explains how to set up the PATH

"Updating the PATH Environment Variable To set the PATH variable permanently, add the full path of the jdk1.8.0\bin directory to the PATH variable. Typically, this full path looks something like C:\Program Files\Java\jdk1.8.0\bin.

Also , refer http://docs.oracle.com/javase/tutorial/getStarted/problems/index.html which points to some common problems while setting up a working environment with JDK.

"Common Error Messages on Microsoft Windows Systems

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

If you receive this error, Windows cannot find the compiler (javac).

Here's one way to tell Windows where to find javac. Suppose you installed the JDK in C:\jdk1.8.0. At the prompt you would type the following command and press Enter: C:\jdk1.8.0\bin\javac HelloWorldApp.java If you choose this option, you'll have to precede your javac and java commands with C:\jdk1.8.0\bin\ each time you compile or run a program. To avoid this extra typing, consult the section Updating the PATH variable in the JDK 8 installation instructions."

Pallavi Sonal
  • 3,661
  • 1
  • 15
  • 19
-2

Can you append java path to your path. This should solve your issue

Adi Kish
  • 79
  • 3
  • 9