Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java runs in cmd, but not from the PowerShell

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?

like image 214
Lewistrick Avatar asked Feb 13 '26 01:02

Lewistrick


2 Answers

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.

like image 105
ares777 Avatar answered Feb 15 '26 13:02

ares777


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

like image 40
KERR Avatar answered Feb 15 '26 15:02

KERR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!