skip to Main Content

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


  1. This could be occuring due to one of the following:

    1. Environment variable not set properly: Check if the JAVA_HOME variable is set properly.
    2. JDK Version mismatch: If there are more than one version of JDKs are installed, make sure the correct one is showing on terminal and same is set on your ENV variable as well.
    3. VS Code/Terminal is not restarted/refreshed after JDK installation: Try to restart it once.

    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.

    Login or Signup to reply.
  2. 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.

    "java.configuration.runtimes": [
      {
        "name": "JavaSE-1.8",
        "path": "/usr/local/jdk1.8.0_201"
      },
      {
        "name": "JavaSE-11",
        "path": "/usr/local/jdk-11.0.3",
        "sources" : "/usr/local/jdk-11.0.3/lib/src.zip",
        "javadoc" : "https://docs.oracle.com/en/java/javase/11/docs/api",
        "default":  true
       },
       {
        "name": "JavaSE-12",
        "path": "/usr/local/jdk-12.0.2"
       },
       {
        "name": "JavaSE-13",
        "path": "/usr/local/jdk-13"
       }
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search