I am new to java and would like to run java code using VS Code.
I have already installed JDK and version can be displayed in Windows’ terminal through command "javac –version" & "java –version".
However when I come to VS Code terminal powershell and command "javac –version", it gave the following error code:
javac : The term 'javac' 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
+ javac --version
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (javac:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I have already installed extension "Extension Pack for Java" for VS Code.
I have also tried to set the path "java.jdt.ls.java.home": "C:Program FilesJavajdk-21" in "setting.json" in VS Code, but the problem still exist.
Can anyone help?
2
Answers
This could be occuring due to one of the following:
Tip: There are some IDEs that provide better environment for learning JAVA, such as Intellij IDEA Community and Eclipse. If you’re new to java and want to learn, I’d suggest to go with one of them.
You need to configure environment variables for your machine and then restart vscode. because the vscode terminal uses the system’s built-in terminal as an integrated terminal, it needs to be re-entered to refresh the configuration.
Alternatively you can open vscode with administrator privileges.
In vscode you can configure JDK using the following setting.