Microsoft has been doing a lot of work to make Windows a better platform for developers. The recent announcement of Windows 11 has sparked a greater interest in using Windows to build for many devs, myself included.
You can use the Windows Subsystem for Linux (WSL), to get a GNU/Linux environment directly on Windows without needing to dual-boot Linux or use a traditional virtual machine.
I wanted to explore how viable WSL is as a full development environment for day-to-day Corda development.
In short: it works near-flawlessly.
Let’s have a look at how we get WSL set up and ready for CorDapp development.
First, install WSL on your machine. The WSL documentation covers this well. I used the manual install process listed, but a simplified install is also available if your version of Windows is compatible. Make sure you set the default WSL version to 2. You might also find it useful to install the optional Windows Terminal listed at the bottom of the article.
Now that you have a Linux environment, let’s install a Java Development Kit (JDK). Corda has been tested and verified to work with Oracle JDK 8 JVM 8u251 and Azul Zulu Enterprise 8u252. Other distributions of the OpenJDK are not officially supported but should be compatible with Corda. If you use Oracle Java 8, make sure to get the `.tar.gz` file for your Linux version – it is likely the “Linux x64 Compressed Archive” file. I found these instructions helpful to complete my Oracle installation.
WSL installed: ✅
JDK installed: ✅
Next, get yourself an IDE!
You’ll need to install IntelliJ IDEA.— the best IDE for CorDapp development. Once you have installed IntelliJ, configure it for use with WSL. Follow the JetBrains guide to connect IntelliJ to the WSL filesystem and JDK. You should now be all set up with the standard environment, so we can take a look at actually getting some CorDapps loaded and running!
We will use ping-pong
sample CorDapp in the Basic
section of our samples-java
(https://github.com/corda/samples-java) or samples-kotlin
(https://github.com/corda/samples-kotlin) repos on GitHub. Create a ~/Documents/Corda
directory in your shiny new WSL filesystem, then clone the sample into it.
It’s now time to open up a CorDapp project in IntelliJ. The WSL filesystem can always be located by typing \\wsl$
into the top bar of the file explorer. You can also use this to navigate to your CorDapp projects in IntelliJ. Locate your ping-pong
sample.
When you first open the project in IntelliJ, it will ask you to load the correct JDK in your Gradle settings. Open your Gradle settings from the link shown below, then select the WSL Gradle JVM from the dropdown box.
Gradle will run and configure the Gradle environment.
We now have a space to build and edit CorDapps!
To deploy our CorDapps, follow the steps in the readme of the CorDapp project and run the command:
`./gradlew clean deployNodes`
Here, the WSL process to spin up nodes differs a bit from other systems. instead of using the `runnodes` script to spawn terminals for each node, run them manually from inside the `build/nodes/<nodename>` directory. Simply open a new terminal tab for each node, cd into the node directory inside of `build/nodes/<nodename>`, and run `java -jar corda.jar` to spool up the node.
This should have you running nodes inside of WSL. Congratulations!
A note on Docker: You can also run your nodes with Docker instead, while still using WSL, it also works pretty well.
To get started with this, you can look at the guide to getting Docker containers working in WSL.
After following the above link to get Docker running in WSL, you can follow one of our great tutorials on running Corda Dockerized, like this one.
Happy coding!