Search code examples
javadebuggingintellij-ideawindows-subsystem-for-linux

Run and Debug Java in WSL 2 with Intellij IDEA on Windows 10


Intellij IDEA is installed on Windows. The java application built with maven requires native libraries (with JNI) and runs on Ubuntu.

Using maven and git on Windows is fine. How can I point Intellij IDEA to use the JDK from WSL so I can create a run/debug configuration that uses the WSL?


Solution

    1. Install Intellij IDEA with version >= 2021.1.
    2. Configure WSL. To work with WSL 2, your Windows version should be 10 build 18917 or later. Make sure you add the needed JDK version in WSL. In order to use Maven, You also need to add a path variable export M2_HOME=/path/to/maven to the .profile file.
    3. Create, open and develop the project in corresponding WSL environment.
    4. Select the project SDK as the JDK configured in WSL.
    5. Ensure that firewalls allow connections using WSL.

    More details: https://www.jetbrains.com/help/idea/2021.1/how-to-use-wsl-development-environment-in-product.html