Back

VSCode Java

How to develop Java programs in VSCode.

How to develop Java programs in VS Code

Pre-Requisites

you should have these software installed:

  1. VS Code
  2. Java Development Kit (JDK)

Install the Java Extension Pack

which contains extensions:

  1. Language Support for Java by Red Hat
  2. Debugger for Java
  3. Java Test Runner
  4. Maven for Java
  5. Project Manager for Java
  6. Visual Studio IntelliCode

Configure JDK

there are 2 configurations: java.home and java.configuration.runtimes.

The former specifies your language server’s execution environment; the latter specifies options for your project’s execution environment.

Command Palette (Ctrl + Shift + P), run:

java: configure java runtime

  1. java.home

    settings -> user settings -> java.home

  2. java.configuration.runtimes

    "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"
       }
    ]
    

Library Configuration

config through java.project.referencedLibaries in settings.json:

"java.project.referencedLibraries": {
    "include": [
        "library/**/*.jar",
        "/home/username/lib/foo.jar"
    ],
    "exclude": [
        "library/sources/**"
    ],
    "sources": {
        "library/bar.jar": "library/sources/bar-src.jar"
    }
}
Built with Hugo
Theme Stack designed by Jimmy