Place your Java project in Pengwin WSL2 and use IntelliJ 2021 to build and run it
Recently JetBrains shipped the IntelliJ 2021.1 Beta 3 with an interesting addition; the possibility to compile and run Java programs whose source code is in WSL2. Everything from the Windows version of the IDE.
https://blog.jetbrains.com/idea/2021/01/intellij-idea-2021-1-eap-1/
https://blog.jetbrains.com/idea/2021/02/intellij-idea-2021-1-eap-5/
Let's create a new Java project (Gradle / Maven) inside Pengwin and run it using IntelliJ from Windows
Install Java in Pengwin
Let's prepare Pengwin for run Java project from IntelliJ:
Install SDK Man from pengwin-setup. SDK Man is a very versatile distribution manager, where you can install and update not only any supported Java version but also Ant, Gradle, Maven, and many other tools. (https://sdkman.io/sdks)
$ pengwin-setup update $ pengwin-setup install PROGRAMMING JAVA $ source /etc/profile.d/sdkman.sh
List the JVM available and install one of them or simply install the default one.
$ sdk list java $ sdk install java 11.0.3.hs-adpt # For example
Or the default
$ sdk install java
Create a new project in IntelliJ
- Create a new Java project. You can choose Java, Gradle, or Maven.
- Choose the just installed JDK from the drop-down
- Remember to create the project in Pengwin home: \\wsl$\WLinux\home\user
- Now refresh the Gradle project (or maven) in IntelliJ and you are ready to start coding, at the IO speed of Linux on Windows:
Additional instructions for Maven
Maven needs some more tweaks:
- If you haven't installed java from apt, create a symbolic link from the default path
$ sudo ln -s "$(which java)" /usr/bin/java $ sudo ln -s "$(which javac)" /usr/bin/javac
- Install Maven using SDKMAN
$ sdk install maven
Permission problems
Sometimes IntelliJ creates the project and its own cache directory as root, and then itself fails due to permission problems. To fix that execute:
$ cd
$ sudo chown user:user -R .cache # Replace 'user' by your username
$ sudo chown user:user -R untitled # Replace 'user' by your username and 'untitled' by your project folder