Setting up Raspberry Pi for Spring boot development

You may want a secondary development machine or you may only have a Raspberry pi for development, either way I want to say that it is very much possible to use Raspberry pi for java and spring boot development. This is a followup to my previous post https://thepro.io/post/minimal-setup-for-a-modest-daily-driver-raspberry-pi-based-development-pc–YO .

spring boot raspberry pi demo

Overclock

These overclock settings are for raspberry pi 4, but you can also overclock for other pi versions, there are plenty of other helpful tutorial blogs for this.

The default cpu frequency for Rpi 4 is set to 700 MHz, increasing to the maximum will make development much more faster than default.

Open config.txt file to edit

 sudo nano /boot/config.txt

uncomment the following parameters or add them if not found and restart the machine.

over_voltage=6
arm_freq=2147
gpu_freq=750

Refer to https://magpi.raspberrypi.org/articles/how-to-overclock-raspberry-pi-4 for more detailed instructions on overclocking.

Install java

To install OpenJDK run the following command in the terminal,

sudo apt update
sudo apt install default-jdk

To check the version installed

java -version
Raspberry Pi OpenJdk version screenshot

Install Maven

To install maven run the following command in the terminal,

sudo apt update
sudo apt install maven

and to check installed maven version

mvn --version
maven version screenshot

Installing Visual Studio Code

You would think but why not eclipse right ?. Well, at the time of writing this post, raspberry pi OS did not have a way of installing latest version of eclipse. The eclipse available from the repository is nearly a decade old and will not work with the latest java version.

Now to install vscode, go to https://code.visualstudio.com/download and download either Arm or Arm 64 debian package, depending on the version of raspberry pi OS you have setup.

To check, run following command in the terminal. If the response contains ‘armv7l’, choose ‘Arm’ and if it contains ‘aarch64’, choose ‘Arm 64’ for 64 bit version of package.

uname -m

once the .deb file is downloaded, Install the package using following command

cd /Downloads
sudo dpkg -i code_*.deb
visual studio code screenshot

Java Support for Visual studio code

Click on extensions tab on the sidebar menu and search for “java extensions” and click install. This will install all the required extension packages required to run and test java applications along with support for code completion and code navigation.

Visual studio code java extension pack

Spring boot development on Visual studio code

Now that we have the IDE ready, let’s create a simple spring boot application.

Go to spring initializr at start.spring.io and put together a demo project and download.

Extract the downloaded project and open with visual studio code.

Since the java extension pack is installed, you should see a Java Overview screen with an alert saying “java project detected would you like to import”. Click yes and proceed with import,

Visual studio code java dashboard screenshot

next, click on the debug tab on the sidebar menu and click on “create a launch.json file” and choose java from the options displayed.

vscode create launch.json file screenshot

This should create the launch file. Click on “Launch DemoApplication” option from the debug dropdown on the debug tab.

vscode launch.json file sample screenshot

Spring boot should now be started on default port 8080. Open browser and navigate to http://localhost:8080 to check if server is running.

Spring boot demo screenshot

This setup is more than enough for spring development, but you can add more spring boot support by installing Spring boot extension Pack.

Go to Extensions tab on the side menu and search for “Spring boot extensions” and click install

Spring Boot Extensions Pack screenshot

That’s it. Happy Coding !