Setting up Java Development on Raspberry Pi

The idea of using the Pi as a machine for java development really excited me. With 8GB ram and quad core arm 64 bit processor and Manjaro Mate as the operating system, it was more than capable of running necessary apps for Java development. I was willing to see how far I can go with this. At minimum I was looking at installing JDK 11, maven, an IDE like IntelliJ and try to run some sample code.

I turned to the trusted sdkman. Installing sdkman was a breeze and few quick commands helped me install java and maven as well.

curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 11.0.16-zulu
sdk install mvn 3.8.6

Time to check if everything is installed correctly

[koolksp@koolksp-rpi ~]$ java -version
openjdk version "11.0.16" 2022-07-19 LTS
OpenJDK Runtime Environment Zulu11.58+15-CA (build 11.0.16+8-LTS)
OpenJDK 64-Bit Server VM Zulu11.58+15-CA (build 11.0.16+8-LTS, mixed mode)
[koolksp@koolksp-rpi ~]$ mvn -version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /home/koolksp/.sdkman/candidates/maven/current
Java version: 11.0.16, vendor: Azul Systems, Inc., runtime: /home/koolksp/.sdkman/candidates/java/11.0.16-zulu
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.56-1-manjaro-arm-rpi", arch: "aarch64", family: "unix"
[koolksp@koolksp-rpi ~]$

For the IDE, IntelliJ IDEA version for linux is a downloadable .tar.gz file. Simply extracting it and running the idea.sh script brings up the IDE. I had to tweak a few system variables and set the PATH for things to work. But once done I had no issue starting the IDE. I quickly created a maven project, added some sample code and went ahead with maven build to create a jar file. Running the code within IntelliJ shows output as expected. Of course it is not blazing fast. Pi does have its limitations, but the fact that it can indeed do all this is a feat. The small single board computer does pack a punch. It will be fun to have some small project developed and tested on the Pi. I plan to extend my dev setup to include spring boot and maybe a tomcat server, just to see how far I can push this tiny beast.

Getting Hands-on With Pacman

Though Manjaro has a graphic utility for adding/removing software, it does ship with pacman which is the the package manager from upstream Arch Linux. On Ubuntu based systems, I was already familiar with apt-get command with its straight forward options, but pacman was little different in terms of the flags it uses to install/update packages. It would take me some time before getting used to it. And while I was still getting a hang of it I knew I would be making ample mistakes on the cli and probably mess something up. There was definitely a better way to handle this elegantly and an opportunity to use my nifty Unix scripting skills.

The official Pacman wiki is detailed enough to understand and use the different options. To use this seamlessly I thought it would be good to write a Unix script as a wrapper over these commands, which will make sure that I just provide the choice of my actions and name of the package for it to work. The script will take care of calling the right commands using sudo ( if required ). This takes away the need to figure out which flags to pass to pacman.

I added options to search for packages, install/remove package, list/remove redundant packages, upgrade system, clear cache etc. Selected menu item simply delegates to the appropriate pacman command, making it a stress-free, seamless execution. Here is the entire script.

#! /usr/bin/sh

while [ true ]
do
        clear
        echo "PACMAN Helper"
        echo "-------------"
        echo "1. Search package"
        echo "2. Install package"
	echo "3. Remove package"
        echo "4. List unused packages"
        echo "5. Remove unused packages"
	echo "6. Update and Upgrade system"
	echo "7. Clean cache"
        echo "0. Exit"
        echo
        read -p "Enter choice: " choice
		echo 

        case $choice in
                0)      clear
			exit
                        ;;
                1)      read -p "Enter package name: " pkg
			(pacman -Qs $pkg; pacman -Ss $pkg) | cat | less
                        ;;
                2)      read -p "Enter package name: " pkg
                        sudo pacman -Syu $pkg
                        ;;
                3)      read -p "Enter package name: " pkg
                        sudo pacman -R $pkg
			read -p "Press any key to continue..." continue
                        ;;
		4)	if [ `pacman -Qdt | wc -l` -gt 0 ];then
				echo -e "Listing unused packages...\n"
				pacman -Qdt
			else
				echo "No unused packages found"
			fi
			read -p "Press any key to continue..." continue
			;;
		5)	if [ `pacman -Qdt | wc -l` -gt 0 ];then
				sudo pacman -Rs $(pacman -Qdtq)
			else
				echo "No unused packages found"
			fi
			read -p "Press any key to continue..." continue
			;;
		6)	sudo pacman -Syu
			read -p "Press any key to continue..." continue
			;;
		7) 	sudo pacman -Sc
			read -p "Press any key to continue..." continue
			;;
                *)      echo "Invalid choice"
                        ;;
        esac
done

Created a ~/.local/bin folder and saved this file as “pacmanhelper”. File permission 744 makes sure no one else is able to change or execute this file. I updated the .bashrc to include this in the PATH.

Here are some screenshots of the script in action.

Pi Land Adventure 3 – Pop OS

The Pi journey continues with Pop OS. I could quickly get started by flashing the latest pi image onto the micro SD card and booting it right away. The official image is a hefty 2.2GB and does take its time to written on the SD card.

First boot was a familiar experience, since I have been using Pop OS as my daily driver for almost a year. And so I was very curious about its ARM spin. The welcome screen asks you to enter the user details, set up a password, allows some quick selection of themes, dock positions etc and you are ready to go. Pop OS has the cosmos desktop with its window tiling feature which is a breeze to use. One thing I noticed though, that the dock does not auto hide which is annoying and wastes valuable screen real estate.

The RAM usage hovers at 1.7 GB which is definitely on the heavy side and the fresh install of the image takes 7.6 GB disk space. WiFi and Bluetooth connectivity is also not an issue.

The list of applications isn’t that exhaustive, the only good thing being that it came with full Libre Office suite. Even Firefox had to be installed as a snap and not native application. It did not have a audio player either. Things weren’t looking as bright. And the biggest gripe I soon discovered was Pop OS’s inability to update/upgrade or install any more software. Repeated attempts to install unmet dependencies and then continue to install applications like gimp, vlc etc failed.

I just felt like stopping here. What good is this OS if it wont allow to install applications esp when preinstalled list does not fully serves its purpose. I understand Pop OS for Raspberry pi is still nascent and may have a long road ahead. Maybe I will revisit this once it is more mature or at least functions better.

Seems the one Raspberry pi image that I was most excited about has fallen way short of my expectations. Partly because I have come to really like Pop OS as my Linux distro of choice for laptop, maybe it is not yet ready for the pi. I do not think I will hang around beyond this point anymore. Time to flash that micro SD card with something else.