3

I just added the java folder to my Environment Variables. When I try to execute, for example, javac HelloWorld.java and java HelloWorld from the Windows command line (cmd), it executes normally. But if I open Windows Powershell and do the same, it says:

javac : The term 'javac' is not recognized as the name of a cmdlet, function, script file, or operable program. Check t
he spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ javac HelloWorld.java
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (javac:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Also, if I compile HelloWorld.java in cmd, it is possible to run java HelloWorld from the Powershell.

How can I execute javac from the Powershell?

Lewistrick
  • 2,649
  • 6
  • 31
  • 42
  • seems like duplicate question, why you just not search SO before posting http://stackoverflow.com/questions/16811332/cannot-run-java-from-the-windows-powershell-command-prompt – ares777 Mar 11 '15 at 08:13
  • I read that question, and it is of no help to me. I have already added the JRE folder to my path environment variable. – Lewistrick Mar 11 '15 at 08:43
  • Please show what you got from $env:path in powershell. Also from cmd echo %path% – ares777 Mar 11 '15 at 09:09
  • I see: `$env:path` in ps doesn't contain the java folder, whereas `echo %path%` in cmd does. The former list is way longer, and does contain this though: `C:\ProgramData\Oracle\Java\javapath`, which is a folder containing shortcuts to files in the jre directory. – Lewistrick Mar 11 '15 at 09:22

3 Answers3

3

Verify what you got from $env:path in powershell. Also from cmd echo %path% If javapath is not contain in powershell path, make sure you add properly.

ares777
  • 3,590
  • 1
  • 22
  • 23
1

Reinstalling Java (same version/installer) fixed this for me. No reboot was required.

KERR
  • 1,312
  • 18
  • 13
1

The JDK entry in your PATH might be in quotes.

I had the same problem, and running $env:Path in PowerShell gave me an output like

C:\Program Files\FooBar;"C:\Program Files\Java\jdk1.8.0_92\bin";C:\Program Files (x86)\Example\whatever;...

Note how the JDK entry is in quotes, but others are not. Apparently, cmd can deal with this, but PowerShell not.

How to fix

  1. Open the system environment variables editor and locate the PATH variable in the list.
  2. Click "Edit...", a list editor pop up. Note how the JDK entry is not listed in quotes there, so we need to edit the raw text.
  3. Click "Edit text..." to get an editor for the raw text, remove quotes there and save everything.
Cedric Reichenbach
  • 8,970
  • 6
  • 54
  • 89