I have Java installed on my machine (the JRE is under C:\Program Files\Java) but I can't run any java command from the Windows PowerShell command prompt.
>>> java -version
java : The term 'java' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ java
+ ~~~~
+ CategoryInfo : ObjectNotFound: (java:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
However, I have noticed that Java does work and that I can run Java commands on the old Windows command prompt. Turns out it's only PowerShell where I can't run those commands.
I have JRE 7 and I'm using Windows PowerShell on Windows 8.
解决方案
In the run dialog box, enter sysdm.cpl
In the window that came up, navigate to Advanced tab. Click on the Environment Variables button.
Add the location of your java installation (the bin directory) to the PATH variable.
;%ProgramFiles%/Java/jre%version%/bin
followed by a ;
Note:
%version% means the java version.