NetBeans 8 and IoT Development
This week at JavaOne, Oracle spoke a lot about what's going into the Java 8 suite of releases. It's a suite because it includes a fresh coordination of Java ME, Java SE, and NetBeans software technology with sweeping changes. There will be an alignment of APIs, libraries, and capabilities between Java ME (both CLDC and CDC) and Java SE, including Java SE Embedded. This is good news and it makes writing code across computers and devices of varying sizes and capacities more uniform. This will become increasingly more important as the Internet of Things (IoT) takes hold in the coming months and years.
To illustrate this, many of the sessions at JavaOne focused on Raspberry Pi devices and the JVMs and tools that are available for this amazing embedded platform. This includes Java ME, Java SE Embedded, and the forthcoming JDK 8.
Java ME and Raspberry Pi
You can develop Java applications for the Raspberry Pi using Java ME Embedded by downloading Java ME here. You can choose either the current version, which is Java ME 3.3 or 3.4 depending on device type, or the early access release of Java ME 8.
Next, as an example to getting started, create a CLDC 1.1 application and write some code. You can test your code with the CLDC device emulator or a Raspberry Pi running Java ME. However, on the Pi, you first need to start a special "user test" application that lets you debug remotely from NetBeans running on your laptop or desktop. To do this, run the following command on your Pi, located in the bin directory of your Java ME 3.3 installation:
< sudo usertest.sh
Next, add the Raspberry Pi as a new device by choosing the NetBeans menu Tools --> Java ME --> Device Selector. Select the "Add a Device" button at the top of the Device Selector pane, enter the IP address of your Pi (which needs to be on, connected, and running usertest.sh as mentioned above), and choose the "Finish" button after it appears in the list in green. Then, in the Java ME project, select the device by IP address with the Project --> Properties window, within the "Platform" section. All of this can be done in Eclipse as well, although the steps vary slightly. For more details, follow the steps listed here.
Java SE Remote Deploy and Debug on Raspberry Pi
You can develop Java applications for Java SE Embedded running on a Raspberry Pi as well. The advantage to this approach is that you’ll be running the same base JVM on your Pi as you run on a server or desktop. The two VMs are byte compatible, and Java SE Embedded supports more APIs and libraries than Java ME Embedded does. A good place to being is the "Getting Started with Java SE Embedded on the Raspberry Pi" document located here.
What's missing for the Java SE developer on the Pi today is the ability to deploy and debug code directly on the Pi from your laptop or desktop computer. Although you can do this with Java ME — as shown above — for Java SE Embedded you need to instead copy your code to the Pi via a tool such as SCP, and then SSH into the Pi and execute it from the command line. Thankfully, with NetBeans 8, this will no longer be the case.
To try this today, download the latest development (early access) version of NetBeans. However, be sure to maintain a working installation of the released version of NetBeans if you depend on it for your day-to-day programming, as the development version isn't yet production ready. This is literally the trunk of the NetBeans development team's code repository, so be careful using it.
Make sure that your Raspberry Pi is on, can be accessed over your LAN, and has the latest version of Java SE Embedded installed on it; click here for an example. Next, fire up the development version of NetBeans (note that it will identify itself as "NetBeans IDE Version 7.4 DEVELOPMENT EDITION") and follow these steps:
- Create a new Java platform by choosing "Java Platforms" from the NetBeans Tools menu.
- Click the "Add Platform" button from the Java Platform Manager window that appears.
- Select "Remote Java Standard Edition" as the platform type, and click the Next button.
- Give your platform a name (i.e. "Pi"), and enter all of the information requested:
The Pi's IP address;
Your username on the Pi, or "root";
That user's password;
The path to where Java SE Embedded is installed on the Pi;
The working directory to place your Java code (i.e., ~/myjavacode/)
Figure 2: Enter the remote platform information.
- Click "Finish."
Figure 1: Select the "Remote Java Standard Edition" platform type.
Next, create your project, and choose this remote Java platform to run. To do this, right-mouse-click on your project in NetBeans' project list, and select Properties from the popup menu. Then select "Run" from the list of Categories in the Project Properties window and select the name of the remote Java platform you created.
Figure 3: Select the remote Java platform as the JVM to run/debug with.
Now, when you run or your debug your project, NetBeans will compile and deploy the artifacts to the Pi, and execute the resulting code on the Pi transparently (although you may be prompted for the remote user's password to perform this operation on your Pi). You can set breakpoints and step through code as though it were running locally on your development machine even though it's running remotely.
Having the ability to perform remote Java application deployment and debugging on a device makes embedded software development even easier. It shows how Java and its tools are getting ready today for the Internet of Things movement of tomorrow.