[Java] How to load library from JAR file with VS Code 《Method without Maven/Gradle》

less than 1 minute read

A memorandum for when you want to read a JAR file directly when you want to program lightly in Java and it is troublesome to set up a build tool.

[Update] of VS Code Java Extensions Pack in April 2020 (https://github.com/microsoft/vscode-java-pack/blob/master/release-notes/v0.9.0.md#work-with-jar- files-directly) can now be read without using Maven / Gradle.

Java Extensions Pack

Java Extension Pack is an extension for creating, debugging, and testing Java programs with VS Code. Install here.

Load JAR file

In the left tab, search for “Referenced Libraries” under “JAVA DEPENDENCIES”. Click the + button next to “Referenced Libraries” to add the JAR file.

Demonstration

Source: https://github.com/microsoft/vscode-java-pack/blob/master/release-notes/v0.9.0.md#work-with-jar-files-directly

If JAVA DEPENDENCIES and Referenced Libraries are not displayed

I don’t know why, but it may not be displayed. Restarting VS Code itself usually fixes the problem.

Default library settings

Default can be set by changing java.project.referencedLibraries in settings.json of VS Code.

settings.json


"java.project.referencedLibraries": [
    "library/**/*.jar"
]