humble
humble

Reputation: 2178

Configuring Java Extension Pack in Remote WSL on VSCode

My question is similar to this. I am trying to work with Java in Remote-WSL using VSCode. According to VSCode guidelines, I should install the Java Extension Pack on WSL. However, when I try to install it I get the following error:

The java.home variable defined in Visual Studio Code settings points to a missing or inaccessible folder (C:\Program Files\Java\jdk-9.0.1)

This is what the Java Extension pack shows when I install it on WSL.

enter image description here

I have been able to resolve this issue if I change the path in java.home to be same as JAVA_HOME in settings.json. However, I need to toggle the path back to C:\Program Files\Java\jdk-9.0.1 manually when working on my local machine and not on Remote-WSL.

Is there a better way to make it work?

PS: I've no clue why it says that JDK_HOME is empty. If I echo $JDK_HOME inside WSL, it shows the path same as JAVA_HOME.

Upvotes: 5

Views: 13603

Answers (4)

Justino Feba
Justino Feba

Reputation: 25

i solved my problem running this comand on WSL

sudo apt install default-jdk

Upvotes: 1

drinkmorewater
drinkmorewater

Reputation: 103

If you want to develop Java in WSL, you need to install JDK in WSL. Now from the way you frame your questions I would assume you have done that (it needs to be installed as a Linux program, so if your JAVA_HOME starts with anything like /mnt/c then you don't actually have it on WSL).

I have been able to resolve this issue if I change the path in java.home to be same as JAVA_HOME in settings.json. However, I need to toggle the path back to C:\Program Files\Java\jdk-9.0.1 manually when working on my local machine and not on Remote-WSL.

The problem you mentioned here is relatively simple to solve. All you need to do is to have a WSL specific settings for java.home, and have the normal setting (i.e. C:\Program Files\Java\jdk-9.0.1) remain in your normal VS Code settings. To access WSL specific settings, use CTRL+SHIFT+P then type "Open Remote Settings".enter image description here

Upvotes: 5

jornh
jornh

Reputation: 1369

Copied answer to one possible problem/solution from the Q above for visibility here:

I have been able to resolve this issue if I change the path in java.home to be same as JAVA_HOME in settings.json. However, I need to toggle the path back to C:\Program Files\Java\jdk-9.0.1 manually when working on my local machine and not on Remote-WSL.

Before installing the Java Extension Pack on the WSL side of things you should have something similar to this (so, yeah --> Click that button!):

enter image description here

Upvotes: 1

Steven-MSFT
Steven-MSFT

Reputation: 8431

I think you should install JDK in WSL.

Upvotes: -2

Related Questions