2 Using NetBeans with the Raspberry Pi Board

Developers can run and debug IMlets on the Raspberry Pi board directly from the NetBeans IDE 8.0 Beta or using the Oracle Java ME SDK 8.0 EA 2. This chapter describes how to add the board to the Device Manager in the Oracle Java ME SDK 8.0 EA and how to debug an IMlet on the board from the NetBeans IDE 8.0 Beta.

Using NetBeans with the Raspberry Pi Board

Running and debugging IMlet projects on the Raspberry Pi board using the NetBeans IDE 8.0 Beta requires the following software:

This chapter assumes that the Raspberry Pi board is already set up and connected to the Windows platform running Oracle Java ME SDK 8.0 EA 2 and NetBeans IDE 8.0 Beta, and that NetBeans IDE 8.0 Beta has already been started.

Adding the Raspberry Pi Board to the Device Manager

Follow these steps to add the Raspberry Pi board to the Device Manager in the Oracle Java ME SDK 8.0 EA 2:

Ensure that the sudo./usertest.sh script in the /bin directory is running on the Raspberry Pi board.

This sample application will obtain an object representing GPIO pin 2 from the PeripheralManager, and attempt to obtain its high/low value.

Including Your Sample IMlet Code

Now you can update the generic project you created with your sample code. In the NetBeans Projects window, you see the sample project with file ME8EmbeddedApplication1.java. Do the following

Right click to select ME8EmbeddedApplication1.java in the Projects window and select Properties.

This displays the ME8EmbeddedApplication1.java Properties window.

To see the path to the location of the ME8EmbeddedApplication1.java file, look in the All Files line. Make a note of this path.

Take the IMlet.java file you created and copy it into the me8embeddedapplication1 directory in the file path you noted.

Delete the file ME8EmbeddedApplication1.java or remove it from the directory.

This changes the content of the NetBeans Project window to the content in the IMlet.java file. (If it does not double-click IMlet.java in the Projects window.)

Clean and build the ME8EmbeddedApplication1 project by clicking on the hammer-and-broom icon in the NetBeans toolbar or by selecting Run > Clean and Build Project (ME8EmbeddedApplication1).

Run the newly cleaned and built ME8EmbeddedApplication1 project by selecting the green right-arrow icon in the NetBeans toolbar or by selecting Run > Run Project (ME8EmbeddedApplication1.)

When the Run is successful, the EmbeddedExternalDevice1 emulator starts with the ME8EmbeddedApplication1 Suite running.

Debugging an IMlet on the Raspberry Pi Board

Follow these steps to debug an IMlet using NetBeans:

Open your IMlet class on the NetBeans editor.

Click once directly on the line number where you want to set a breakpoint. The line number is replaced by a red square and the line is highlighted in red.

Select Debug -> Debug Project or use the Debug button on the toolbar.

The debugger connects to the debug agent on the board and the program execution stops at your breakpoint.

Accessing Peripherals

Applications that require access to Device Access APIs must request appropriate permissions in JAD files. For more information on using the Device Access APIs, please see the Device Access API - Version 8 specification and the associated Javadocs at the following site:

Signing the Application with API Permissions

First, the JAD file must have the proper API permissions. Here is how to sign the application both in NetBeans and without an IDE.

In NetBeans, right-click the project name (ME8EmbeddedApplication1 in this example) and choose Properties. Select Application Descriptor, then in the resulting pane, select API Permissions. Click the Add... button, and add the com.oracle.deviceaccess.gpio API, as shown in Figure 2-5. Click OK to close the project properties dialog.

Method #1: Signing Application with a Local Certificate

The first method is more complex, but is the preferred route for applications that are widely distributed. Here are the instructions on how to setup a keystore with a local certificate that can be used to sign the applications.

Generate a new self-signed certificate with the following command on the desktop, using the keytool that is shipped with the Java SE JDK.

This command will generate a 2048-bit RSA key pair and a self-signed certificate, placing them in a new keystore with a keystore password of spass and a key password of kpass that is valid for 360 days. Feel free to change both passwords as you see fit.

Copy the appdb/_main.ks keystore file from the Raspberry Pi over to the desktop using an sftp client or scp command and perform the following command using the mekeytool.exe command (or alternatively java -jar MEKeyTool.jar... if your distribution contains only that) that ships with the Oracle Java ME SDK 8 distribution.

This will import the information in mykeystore.ks you just created to the _main.ks keystore. Once this is completed, copy the certs directory back to the Raspberry Pi an sftp client or scp command.

Use the following command to sign your application before deploying to the Raspberry Pi board.

> jarsigner -keystore mykeystore.ks -storepass spass app.jad myalias

Method #2: Using NullAuthenticationProvider

This method allows to bypass a certificate check and execute unsigned applications as if they were signed and given all requested permissions. This method should be used only for development and debugging. Final testing must be done using a real certificate as described in method #1.

To use NullAuthenticationProvider, set the following property in the jwc_properties.ini file on the Raspberry Pi board: