Skip to content

Conversation

@tsmaeder
Copy link
Contributor

@tsmaeder tsmaeder commented Sep 17, 2025

This adds a VS Code command that

  1. Opens a "Open Directory" dialog to select the root of a VM install
  2. Allows to select a "Known JRE Name" for the VM install
  3. If all goes well, adds an entry to the user settings

Fixes #4161

Copy link
Member

@rgrunber rgrunber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems mostly fine. Just be aware this overlaps with https://github.com/microsoft/vscode-java-pack/blob/main/src/java-runtime/index.ts and it probably would have been ideal to move that page here.


export namespace JavaRuntimes {
export async function initialize(context: vscode.ExtensionContext): Promise<void> {
context.subscriptions.push(vscode.commands.registerCommand('java.runtimes.add', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably add "java.runtimes.add" to Commands.

Copy link
Collaborator

@fbricon fbricon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rebase against the main branch? JavaSE-25 is available now.

const config = vscode.workspace.getConfiguration('java.configuration').get('runtimes');
if (Array.isArray(config)) {
if (config.some(r => r.path === directory[0].fsPath)) {
vscode.window.showErrorMessage(`JDK Directory ${directory[0].fsPath} already configured`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No you need to ensure uniqueness of the jre name.

Screenshot 2025-10-09 at 10 09 08

It's OK having the same JDK used for 2 runtimes, eg. use JDK 11 for JavaSE-11 and JavaSE-1.8

if (config.some(r => r.path === directory[0].fsPath)) {
vscode.window.showErrorMessage(`JDK Directory ${directory[0].fsPath} already configured`);
} else {
const name = await vscode.window.showQuickPick(getSupportedJreNames(), {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would improve it by:

  • detecting the java version of the selected path
  • preselect the matching execution environment name
  • filter out incompatible environments, i.e don't show JavaSE-22 and above if you selected a JDK 21.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also pre Java 8 support has been dropped over a year ago. Can you remove the J2SE-1.5 ... JavaSE-7 values in package.json

Comment on lines 32 to 33
vscode.workspace.getConfiguration('java.configuration').update('runtimes', config, vscode.ConfigurationTarget.Global);
vscode.window.showInformationMessage(`JDK Directory ${directory[0].fsPath} added`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be executed only if the quickpick was complete. If I press ESC while the wizard is open, I see the "...added" message.

@tsmaeder tsmaeder force-pushed the 4161_add_jdk_command branch from 3c9b691 to cbe1b37 Compare November 7, 2025 12:38
@tsmaeder tsmaeder requested a review from fbricon November 7, 2025 12:38
if (runtime) {
const config = vscode.workspace.getConfiguration('java.configuration').get('runtimes');
if (Array.isArray(config)) {
const candidates = getSupportedJreNames().filter(name => !config.some(r => r.name === name) && compatible(runtime, name));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I would not prevent overriding existing JRE Mappings, e.g. I want to switch from one JDK 11.0.0 to 11.0.1
  • versions should be sorted by most recent version 1st

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Command to add a JVM install

3 participants