A Visual Studio Code extension that helps you discover Java runtimes and add them to the VS Code Java runtime configuration.
Requirements
- VS Code 1.100 or newer
- The Java extension reads and uses
java.configuration.runtimes - Access to the local filesystem where JDKs or JREs are installed
Command
- Java Runtimes: Scan Folders and Configure
What It Does
- Prompts for one or more root folders.
- Scans recursively for Java installations.
- Uses the runtime root folder name as the
namevalue. - If the folder name does not contain the detected Java version, appends
_<version>. - Adds discovered Java homes to the
java.configuration.runtimessetting. - Adds
sourcesandjavadocwhen those paths are detected. - Prompts for which runtime should be the default for the current workspace and stores it in workspace settings.
How It Works
- Run the command from the Command Palette.
- Select one or more root folders to scan.
- The extension searches recursively for directories that contain
bin/javaorbin/java.exe. - If
javacis present, the runtime is treated as a JDK; otherwise it is treated as a JRE. - New runtimes are appended to
java.configuration.runtimesin user settings. - You are prompted to choose which runtime should be the default for the current workspace.
Runtime Naming Rules
- The runtime
namestarts with the Java home folder name. - If the detected Java version is already contained in the folder name, the folder name is used as-is.
- If the version is missing from the folder name, the extension appends
_<version>. - If sources or javadoc are found, they are added to the runtime entry.
Example Workflow
- Open the Command Palette.
- Run
Java Runtimes: Scan Folders and Configure. - Select a folder such as
/usr/lib/jvmorC:\Java. - Review the detected runtimes.
- Choose the default runtime for the current workspace when prompted.
Example Runtime Entry
"java.configuration.runtimes": [
{
"name": "java-18-openjdk",
"path": "/usr/lib/jvm/java-18-openjdk",
"sources": "/usr/lib/jvm/java-18-openjdk/lib/src.zip",
"javadoc": "/usr/share/javadoc/java-18-openjdk/api",
"default": true
}
]
Limitations
- The extension is intended for local filesystem runtimes.
- Virtual workspaces are not supported.
- Existing runtime entries are preserved and not rewritten unless the same path is newly added.
Development
- Install dependencies:
npm install - Build:
npm run compile - Run tests:
npm test - Package VSIX:
npm run package
Testing
The repository includes a VS Code extension test runner based on @vscode/test-electron and Mocha. The test suite validates command registration and the runtime naming/version helper logic.
Troubleshooting
- If no runtimes are found, verify the selected directory contains JDK or JRE installations with
bin/java. - If sources or javadoc are missing, verify the runtime installation includes
lib/src.zip,docs/api,javadoc/api, or a matching shared javadoc directory. - If packaging fails, run
npm run compilefirst and confirm the repository is in a packageable state.
License
EPL-2.0