Channels ▼

Eric Bruno

Dr. Dobb's Bloggers

NetBeans 8 and IoT Development

September 27, 2013

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:

  1. Create a new Java platform by choosing "Java Platforms" from the NetBeans Tools menu.
  2. Click the "Add Platform" button from the Java Platform Manager window that appears.
  3. Select "Remote Java Standard Edition" as the platform type, and click the Next button.
  4. NetBeans
    Figure 1: Select the "Remote Java Standard Edition" platform type.

  5. 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/)


    NetBeansPlatformType
    Figure 2: Enter the remote platform information.

  6. Click "Finish."

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.

RemoteJava
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.

Happy coding!
-EJB

Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 


Dr. Dobb's TV