I\'m using PowerShell on Windows 2012 server, and I deleted all the java commands from System32, reinstalled jdk, set JAVA_HOME and Path to point at the new installation. An
1) My default JAVA_HOME is:
echo %JAVA_HOME%
D:\Program Files\Java\jdk1.7.0_25
<= The installer automagically configures this when you install a JRE
2) My default %PATH% does not include any Java
3) I'm able to run (but not compile) Java from a Windows command prompt:
java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
4) I'm also able to do exactly the same from inside Powershell (or from a .ps1 Powershell script):
PS D:\temp> java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
I deleted all the java commands from System32
This is why Windows can't find java.exe. The default JRE installation puts Java into your System32 directory, which is where CMD and Powershell usually find it.
You can fix this for your system by running the following from an admin shell. This creates a copy of java.exe in your Windows directory. (You can also probably get away with a soft link)
fsutil hardlink create (join-path $env:SystemRoot 'java.exe') (join-path $env:JAVA_HOME 'bin\java.exe')
If you don't want to modify your Windows directory (or can't), you can always set an alias to use in your Powershell session.
Set-Alias -Name java -Value (Join-Path $env:JAVA_HOME 'bin\java.exe')
Run that line in your current session and running java
from the command line should work correctly. Add it to your $PROFILE
if you want it to work from all future Powershell sessions.
I suspect you're setting PATH to be the JDK/JRE folder which doesn't contain the java executable, as it's in the bin/ subdirectory...