JAX London 2014: A retrospective
Java Raspberries

How to deploy, debug and profile Java on the Raspberry Pi

Geertjan Wielenga
rp
Raspberry-Pi Model-B Rev2 via Shutterstock

Raspberry Pi experts from around the world talk us through the nitty-gritty of Java on the Raspberry Pi.

There is something magical about the Raspberry Pi. Is it a hype? Is it for hobbyists only? Is it the basis of the refrigerator of the future? As you’re putting the fidgety pieces and wires together an elderly man walks by muttering: “Ah, yes, just like when I had to put my radio together myself, 50 years ago.” Once you have set up a Raspberry Pi, the next step is to install “JDK8 for Arm” on it. Here is how, on the command line of the Raspberry Pi:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install oracle-java8-jdk
Once you have done that, you need: Putty, WinSCP, SSH, and other command line tools, right? Wrong. You can simply register JDK 8 for ARM in NetBeans IDE (as shown above). None other than James Gosling himself has done this for his robots at LiquidRobotics.
“After having spoken about the ‘Internet of Things’ for decades, I’m thrilled by the extent to which, for ordinary developers, this has been exploding beyond cell phones. NetBeans embedded support makes this development painless, fluid, and fast-paced.  Being able to debug a running robot, at sea – or wherever your robot goes – from a thousand miles away, is truly life-altering.” James Gosling
Indeed, once the JDK on the Raspberry Pi is registered in NetBeans IDE, all the clunkiness of working with Java on the Raspberry Pi instantly disappears.
“Initially, when we started development of our PiDome home automation system, we used Putty and WinSCP to build and copy JAR files to the Raspberry Pi, together with the Java debugger on the Raspberry Pi itself. While this took a lot of time, a variety of resources on the Raspberry Pi were used, so that debugger results were affected. We discovered that NetBeans handles all of these activities for us. Firstly, we’ve registered our Raspberry Pi as a remote platform in NetBeans. Secondly, we use the local debugger on our PC instead of the one on the Raspberry Pi, which has made development more then ten times faster than before. On top of everything else, we now no longer need to have an extra mouse, keyboard, and display attached to the Raspberry Pi!” John Sirach, founder and project lead of PiDome (pidome.org)
 “I’ve been developing JavaFX based applications for the Raspberry Pi since the very early versions of JDK 8, dealing with Putty, SSH, FTP, and VNC solutions for sending the JAR from my laptop, launching the application, and finally closing it. Debugging was a tough process. In the meantime, I have found that NetBeans can manage all these tasks in one go, and I went for it without any hesitation at all. In a heartbeat, I managed to put it all to work — NetBeans now takes care of everything, once you set the required data connection parameters. Remote debugging is so easy now, too.” José Pereda Llamas, Assistant Professor at the School of Industrial Engineering, University of Valladolid, Spain (uva.es)
As James Gosling indicates above, deploying Java apps to the Raspberry Pi is only the beginning. After all, you also need to debug and troubleshoot those applications, don’t you? Just like any other application.
“NetBeans 8 is a truly revolutionary tool for Raspberry Pi development. You can develop in NetBeans on your local laptop and, during the build phase, your software will automatically be copied to the Raspberry Pi. However, you can then debug your program, that is running on the Raspberry Pi, from within NetBeans. The program itself will be automatically executed on the Raspberry Pi with the appropriate parameters for remote debugging. NetBeans makes embedded development as easy as normal Java SE development. And, it is really fun to develop with these tools!” Johannes Weigend, chief architect, manager, and founder of QAware (qaware.de)
“The fact that you can program locally in NetBeans on your PC while compiling your code on your Raspberry Pi makes development very comfortable and easy due to the power provided by the PC compared to the Raspberry Pi. NetBeans debugging tools are also very helpful and reduce time normally taken with the limited toolset on the Raspberry Pi. No more than a couple of minutes are needed to find a tutorial on the NetBeans site on how to do remote compilation. After that, I was good to go in no time at all.” Conrad Vassallo, Malta College of Arts, Science & Technology (mcast.edu.mt)

Here is a YouTube clip showing the intuitive debugging, including stepping through code deployed on the Raspberry Pi:

Moreover, what you want is an environment that is comprehensive, encompassing not only Java embedded tools, as described above, but all kinds of other tools too. For example, how about putting your Raspberry Pi applications in GitHub directly from the same environment where you’re coding, debugging, and profiling them?
“NetBeans support for embedded Java development improves with each new release. Everything that you need to do when developing for Java embedded devices can be done without moving out of NetBeans. The ability to create and deploy remote Java platforms in different embedded flavors directly from NetBeans is a real time-saver. Using Java embedded on the Raspberry Pi and on iMX6 based devices, with helpers such as the embedded terminal and compact Java profile support, is a real pleasure. Additional future enhancements in the pipeline prove that NetBeans developers listen to the community and implement features that are really needed.” Sławek Mikuła, Lead Developer at ByteBites (bytebites.com)
“Embedded devices like the Raspberry PI can be fun to develop for, but with their constrained resources they aren’t necessarily fun to develop on. Setting up NetBeans with a Remote JDK makes running your code on the embedded device simple without ever needing to leave the environment of a powerful IDE. With NetBeans handling the details of transferring your program to the device and running or debugging it there, it’s as easy as regular desktop development.” Scott Palmer, Senior Software Developer at Imagine Communications (imaginecommunications.com)
Get started via the instructions in “Using Oracle Java SE Embedded Support in NetBeans IDE”, referred to below:
“If you know the few details described in the tutorial that are needed to install the JDK on the Raspberry Pi, you can manage in about 15 minutes to get your first “Hello World” program running on it. The NetBeans remote debugging feature, in particular, is awesome and you are nearly as fast as if you were debugging on your local PC. If more people would know about these features, they would surely use Java and NetBeans for their remote programming tasks.” Andreas Lüdtke, independent software developer
“I was really surprised to find I could add a remote platform to NetBeans. Genius! I installed Java SE 8 on the Raspberry Pi using ‘apt-get’ and then simply added it as a remote platform to NetBeans 8 on my Mac. Now the Raspberry Pi is even more of a real computer, thanks to NetBeans!” Fred Zuijdendorp, independent consultant, developer, and teacher
As a final point, while other tools exist that do similar things, you really need a fully integrated solution that is comprehensive and that works out of the box as soon as you start it up, without needing special configuration and plugin installation steps.
“For me, the new NetBeans 8 tools for embedded devices are really a decisive step forward. In particular, my favourite feature is the smooth debugging of GPIO events and measured values, as well as the profiling of JavaFX UIs on small devices. While there are also IoT-related solutions in other established IDEs, such as Eclipse and IntelliJ IDEA, NetBeans 8 offers the most seamless integration of tools for remote deployment, debugging, and profiling of ‘Internet of Things’ Java applications.” Jens Deters, independent Java/JavaFX/JEE developer

Imagine, if you will, the experience of working with Java on the Raspberry being identical to working with any other kind of Java application on your local PC. From creating the skeleton application, to developing it, to debugging, and profiling. All the skills you have already developed can seamlessly be transferred to the new environment of the Raspberry Pi, as well as other embedded devices, with Java and NetBeans.

Author
Geertjan Wielenga

Geertjan Wielenga

All Posts by Geertjan Wielenga

Geertjan Wielenga is a principal product manager in Oracle for NetBeans and has been a member of the NetBeans Team since 2004
Comments
comments powered by Disqus