VSCode create Big Data Maven/Java Project on WSL2 Ubuntu on Windows

Vikas Sharma
4 min readJan 21, 2022

--

Create Maven project in WSL while running VSCode in Windows (Remote development on WSL Ubuntu or any other Linux OS)

For Hadoop, Hive, Sqoop, Zookeeper, and other big data components and packages installation check my previous stories 1, 2, 3.

Launch VSCode in windows and remotely connect to WSL2 Ubuntu 20.04 (or other Linux OS on WSL) so that code can be built, executed, debugged and deployed directly in Linux environment.

About remote VSCode usage on windows check Microsoft official link.

Following extensions I have configured (if not all available to install then install whatever you can) locally on windows:

Local Installed on Windows
Local Installed on Windows

I have installed JDK 8 on WSL and hence this article explains how to deal with a problem when WSL by default runs on JDK 11 (java builds may fail on WSL if JAVA version installed on WSL is lesser than 11).

In case you have JDk/JRE 11 installed on WSL then skip the preference setting below while continuing other steps.

NOTE: At this point, I have a JDK (SE) 8 locally installed on windows too. Only required if JAR is build locally on windows and then deployed on WSL.

Preferences

Open VSCode, press ctrl+shift+p, type Open Preference Settings (UI) and select that. Type javahome in search and on tab “Remote [WSL….”, click on red highlighted button :

Copy paste below code in the JSON file, it should look like this(mine looks like this), select all pasted text, right click, format, save and close:

{
“java.configuration.runtimes”: [
{
“name”: “JavaSE-1.8”,
“path”: “/usr/lib/jvm/java-8-openjdk-amd64”,
},
{
“name”: “JavaSE-11”,
“path”: “/usr/lib/jvm/java-11-openjdk-amd64”,
},
],
}

Connect to WSL and create Maven Project

Press ctrl+shift+p to open command line and type as shown below:

Choose Ubuntu-20.04 or choice of your Linux installed:

Click on Extensions on the left most boundary (list of buttons in VSCode), and make sure to install extensions (if not all available to install then install whatever you can):

Another windows opens up with WSL connected. Thereafter again press ctrl+shift+p and type as shown below and enter(check in bottom left it shows in blue WSL Ubuntu connected successfully):

Thereafter select options (pressing enter)as below:

  1. maven-archetype-quickstart
  2. 1.4
  3. Group ID of your choice
  4. Artifact ID of your choice
  5. Choose the default location that pops up (/home/hadoop/.vscode-server/data/Machine/), if you choose some other location, the process fails.
  6. Once the project creation starts in Terminal, thereafter give some information like version number and ‘Y’ as and when asked.
  7. Project successfull

From file menu Open Folder and choose same location, it takes some time to open the project and its dependencies:

/home/hadoop/.vscode-server/data/Machine/YourProjectNameFolder

Open a .java file and press F5 for debugging or ctrl+F5 to execute and run . Check output in terminal:

Add path for maven in both Windows and WSL Ubuntu preference settings in VSCOde:

For Windows, install maven from link :

https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.zip

Extact maven and put it in c:program files such that path becomes:

C:\Program Files\apache-maven-3.8.4\binvs

For WSL Ubuntu:

wget https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gztar -xvzf apache-maven-3.8.4-bin.tar.gzsudo mv apache-maven-3.8.4-bin.tar.gz mavensudo mv maven /usr/local

While VSCode is connected to WSL, open preferences by ctrl+shift+p, type Preferences: Open Settings (UI), type maven in search field, make changes like this:

--

--