How to develop Java programs in VS Code
Pre-Requisites
you should have these software installed:
- VS Code
- Java Development Kit (JDK)
Install the Java Extension Pack
which contains extensions:
- Language Support for Java by Red Hat
- Debugger for Java
- Java Test Runner
- Maven for Java
- Project Manager for Java
- 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
-
java.home
settings -> user settings -> java.home
-
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"
}
}