Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java not recognized on PowerShell

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. And I still get the following error:

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
like image 605
blueseal Avatar asked Feb 04 '15 22:02

blueseal


People also ask

How do I know if Java is installed in PowerShell?

PowerShell – Check Java Version on Remote Computers You can also get the list of servers or computers in AD using the Get-ADComputer cmdlet from the RSAT-AD-PowerShell module. As a result, you will have a table with the list of computers/servers and Java versions installed on them.

How do I check if Java is installed?

Select Start -> Control Panel -> Add/Remove Programs, Here you can see the list of installed software on your computer. The list is displayed in alphabetical order. Check if Java name is listed in the installed software list.

Why Java is not working in CMD?

The Java is not recognized as an internal or external command in Command Prompt error occurs if the environment variables are not configured correctly. By adding the correct path to an environment variable, you can resolve the issue. If the error persists, try installing the compatible Java version.

Why is PowerShell not recognizing commands?

Cause. This is caused by the user (or system) PATH environment variable not containing the directory where the PowerShell executable resides. It's usually located at C:\Windows\System32\WindowsPowerShell\v1.


1 Answers

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.

like image 71
Ryan Bemrose Avatar answered Oct 03 '22 08:10

Ryan Bemrose