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.

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.
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".
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.hometo be same asJAVA_HOMEinsettings.json. However, I need to toggle the path back toC:\Program Files\Java\jdk-9.0.1manually 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!):

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With