Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 480
humble Avatar asked Mar 27 '20 19:03

humble


2 Answers

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

like image 162
shengjiex98 Avatar answered Sep 30 '22 09:09

shengjiex98


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

like image 36
jornh Avatar answered Sep 30 '22 09:09

jornh