This chapter describes how to run IMlets using the command-line shell interface, the Application Management System (AMS) command-line interface (CLI), and NetBeans IDE. You learn how to add the board to the Device Connections Manager in the Oracle Java ME SDK and how to debug an IMlet on the board from the NetBeans IDE.
Topics:
There are several ways to use the Oracle Java ME Embedded platform on the Raspberry Pi board.
Directly run commands using a command-line shell interface or logging in using the ssh
protocol.
Manually start a Developer Agent program on the desktop host and run commands using the Application Management System (AMS).
Run NetBeans IDE.
The Java ME Embedded runtime delivery might include preinstalled IMlets. When started, the Java ME runtime checks availability of preinstalled IMlets and automatically installs them on the Raspberry Pi board, if they were not installed during previous runs.
Preinstalled IMlet files are located in the /appdb
directory on the board and have the following format:
/appdb/Preinstalled_app_<num>.jar
/appdb/Preinstalled_app_<num>.jad
In this notation, <num>
stands for a preinstalled IMlet sequence number. Can be any number starting from 1.
You can run IMlets directly on the Raspberry Pi board by using the commands shown in Table 2-1.
Table 2-1 Raspberry PiShell Commands
Syntax | Description |
---|---|
|
List all installed IMlet suites and their status or show the detail of a single suite. |
|
Install an IMlet using the specified JAR file. |
|
Remove an installed IMlet. |
|
Run the specified IMlet or the default if none is specified. All logging information from the IMlet appears in the standard output of this command. |
Note:
The term IMlet, in the context of theOracle Java ME Embedded command-line interface (CLI) and references in this chapter, is synonymous with MIDlet.
The following is a typical example of using the commands to install, list, run, and remove an Oracle Java ME Embedded application on the Raspberry Pi Pi board. Most commands can be terminated with the Ctrl-C key combination if they become unresponsive.
First, install the application using the installMidlet.sh
command, specifying its location on the local file system.
pi@raspberrypi ~/bin $ ./installMidlet.sh /home/pi/EmbeddedTestProject.jar Java is starting. Press Ctrl+C to exit The suite was successfully installed, ID: 2
After an IMlet is installed, note its ID: in this case, it is 2. Next, verify it using the listMidlets.sh
command.
pi@raspberrypi ~/bin $ ./listMidlets.sh Java is starting. Press Ctrl-C to exit Suite: 2 Name: EmbeddedTestProject Version: 1.0 Vendor: Vendor MIDlets: MIDlet: GPIODemo
You can run any installed IMlet using the runSuite.sh
command. This command runs the IMlet that was just installed, passing any logging information to the standard output of this command. Note that you can press the Ctrl-C key to exit from this command, which will terminate the application.
pi@raspberrypi ~/bin $ ./runSuite.sh 2 Java is starting. Press Ctrl-C to exit Starting - GPIODemo
You can use the removeMidlet.sh
command to remove any installed IMlet.
pi@raspberrypi ~/bin $ ./removeMidlet.sh 2 Java is starting. Press Ctrl-C to exit Suite removed pi@raspberrypi ~/bin $
You can verify the results by using the listMidlets.sh
command.
pi@raspberrypi ~/bin $ ./listMidlets.sh Java is starting. Press Ctrl-C to exit No suites installed
The Developer Agent program runs on the Windows or Linux desktop and transmits all communication to and from the Oracle Java ME Embedded executable file on the Raspberry Pi board.
You can start the Developer Agent program on the desktop host computer either in a server or a client mode. The server mode is used by default. The client mode must be configured in the jwc_properties.ini
file.
To configure a client mode connection, edit the jwc_properties.ini
file in the bin
directory on the Raspberry Pi board as follows.
proxy_connection_mode = client proxy.client_connection_address = <IP address>
where <IP address> is the IP address of the desktop host computer running the Developer Agent program.
The Developer Agent program is the proxy.jar file inside the util
directory of the Oracle Java ME Embedded distribution.
To install the Developer Agent program, follow these steps:
/appdb
and /bin
directories.When using the Developer Agent in a server mode, it is important that you first started the Java runtime on the Raspberry Pi board to allow access to the AMS.
To start the Developer Agent program, follow these steps:
bin
directory on the Raspberry Pi board and run the ./usertest.sh
command:
pi@raspberry ~ /pi/bin $ ./usertest.sh
util
directory on your desktop host and enter the following command.
C:\mydir\util> java -jar proxy.jar -socket <RPI IP ADDRESS>
You should see an output similar to the following:
Trying to open socket connection with device: <IP Address>:2201 Connected to the socket Socket[addr=/<IP address>, port=2201, localport=54784] Open channel 8 with hash 0x390df07e notifyResponse AVAILABLE_RESPONSE on channel 8 Channel 8 CLOSED -> AVAILABLE Open channel 9 with hash 0x0
After the Developer Agent starts, use the AMS CLI.
When using the Developer Agent in a client mode, ensure that you configured the client mode as described in the Configuring Client Mode Connection.
To start the Developer Agent program, use these steps:
usertest.sh
command in the /bin
directory:
pi@raspberry ~ /bin $ ./usertest.sh
util
directory on your desktop host and enter the following command.
C:\mydir\util> java -jar proxy.jar
You should see an output similar to the following:
Starting with default parameters: -ServerSocketPort 2200 -jdbport 2801 Channel 8 CLOSED -> AVAILABLE Waiting for device connections on port 2200
After the Developer Agent starts, use the AMS CLI.
The Oracle Java ME Embedded software enables you to set up a secured channel between the device and the Developer Agent so that the commands are sent over the TLS-encrypted channel. This section contains the following topics:
Generate the Developer Agent connection CA certificate by performing the Java SE keytool command:
keytool.exe -genkeypair -keystore <JKS keystore file> -alias <keypair alias> -keyalg RSA -keysize 4096 -validity 7305 -storepass <keystore password> -keypass <keypair password>
Install the Developer Agent CA Certificate on your device by performing the CLI command while the device and Developer Agent are being connected:
ks-import -proxy -keystore <JKS keystore file> -storepass <keystore password> -keypass <keypair password> -alias <keypair alias>
This command installs the CA certificate to the /appdb/cert_proxy
directory.
To configure the Java runtime properties involved in establishing a secured connection to the Developer Agent, set the following properties:
proxy.certificate=
<CA certificate name>
proxy.secured=true
After the secured connection to the Developer Agent is configured, restart the Developer Agent using the following command:
java -jar proxy.jar -socket 127.0.0.1 -socketPort 51300 -secureConnection -keystoreFile <JKS keystore file> -keystorePassword <keystore password> -keypairAlias <keypair alias> -keypairPassword <keypair password> -cliport 65002
To run IMlets on the Raspberry Pi board using the AMS CLI, you must first make a raw connection to the AMS CLI and then use commands.
This section contains the following topics:
Before making a raw connection to the AMS CLI ensure that you started the Developer Agent program on the desktop host and the Java runtime - on the Raspberry Pi board unless the Developer Agent was started automatically by Java ME SDK.
To make a raw connection to the AMS CLI, perform the following.
A connection to localhost
and the port 65002 is shown in Figure 2-1.
Figure 2-1 Using PuTTY to Connect to the Command-Line Interface
[画像:Description of Figure 2-1 follows]The window from port 65002 provides a CLI as shown in Figure 2-2.
Figure 2-2 Command-Line Interface to Raspberry Pi
[画像:Description of Figure 2-2 follows]Note:
The CLI feature in this Oracle Java ME Embedded software release is provided only as a concept for your reference. It uses connections that are not secure, without encryption, authentication, or authorization.
For a complete list of CLI commands, see Using the Command Line Interface in Oracle Java ME Embedded Developer's Guide.
Here is a typical example of using the AMS to install, list, run, and remove an Oracle Java ME Embedded application on the board:
oracle>> ams-install file:///C:/some/directory/hello.jar hostdownload <<ams-install,start install,file:///C:/some/directory/hello.jar <<ams-install,install status: stage DONE, 0% <<ams-install,install status: stage DONE, 100% <<ams-install,OK,Install success oracle>> ams-install http://www.example.com/netdemo.jar <<ams-install,start install,http://www.example.com/netdemo.jar <<ams-install,install status: stage DONE, 0% <<ams-install,install status: stage DONE, 100% <<ams-install,OK,Install success oracle>> ams-install http://www.example.com/notthere.jar <<ams-install,start install,http://www.example.com/notthere.jar <<ams-install,FAIL,errorCode=103 (OTHER_ERROR)
Note that the final installation example failed with an error code and matching description.
Similarly, install an additional IMlet: rs232dem
. After an IMlet is installed, verify it using the ams-list
command. Each IMlet has been assigned a number by the AMS for convenience.
oracle>> ams-list <<ams-list,0.hello|Oracle,STOPPED <<ams-list,1.netdemo|Oracle,STOPPED <<ams-list,2.rs232dem|Oracle,RUNNING <<ams-list,OK,3 suites are installed
You can use the ams-remove
command to remove any installed IMlet.
oracle>> ams-remove 0 <<ams-remove,OK,hello removed
The results can again be verified with the ams-list
command.
oracle>> ams-list <<ams-list,1.netdemo|Oracle,STOPPED <<ams-list,2.rs232dem|Oracle,RUNNING <<ams-list,OK,2 suites are installed
Finally, start the IMlet using the ams-run
command. The application can be terminated with the ams-stop
command.
oracle>> ams-run 1 <<ams-run,OK,started
oracle>> ams-list <<ams-list,1.netdemo|Oracle,RUNNING <<ams-list,2.rs232dem|Oracle,RUNNING <<ams-list,OK,2 suites are installed
Topics:
Running and debugging IMlet projects on the Raspberry Pi board using the NetBeans IDE 8.1 requires the following software:
NetBeans IDE 8.1 with Java ME 8.3 support
Oracle Java ME SDK 8.3
Oracle Java ME SDK 8.3 plugins
For complete instructions about installing Oracle Java ME SDK 8.3, the NetBeans IDE 8.1, and Oracle Java ME SDK 8.3 plug-ins for NetBeans, see Oracle Java ME SDK Developer's Guide.
Note:
This chapter assumes that the Raspberry Pi board is already set up and connected to the Windows or Linux platform running Oracle Java ME SDK8.3 and that NetBeans IDE 8.1 has already been started.
If you want to use the Raspberry Pi with NetBeans, you must first add the Raspberry Pi to the Device Connection Manager in Oracle Java ME SDK 8.3 as follows.
usertest.sh
script in the /bin
directory is running on the Raspberry Pi board./bin
) directory and click its icon in the system tray. A Device Connections Manager window is shown in Figure 2-3.
Figure 2-3 Device Connections Manager Window
[画像:Description of Figure 2-3 follows]Figure 2-4 Device Connections Manager Window with Raspberry Pi Connected
[画像:Description of Figure 2-4 follows]There are two ways to assign the Raspberry Pi board to your project:
After you assign the board to your project, clicking Run Project in the NetBeans IDE runs your IMlet on the board instead of on the emulator.
If you already have an existing NetBeans project with an IMlet that you want to run or debug on the board, follow these steps:
Figure 2-5 Adding a Device to Your Project
[画像:Description of Figure 2-5 follows]Create a new NetBeans project with the name ME8EmbeddedApplication1
and assign the Raspberry Pi board to it as described in Creating a Java ME Embedded Application Project in NetBeans IDE in the Oracle Java ME SDK Developer's Guide .
This section describes how to create and run a sample application. This sample application obtains an object representing GPIO pin 2 from the DeviceManager
object, and tries to obtain its high/low value.
In the NetBeans Projects window, you see the sample project with the file ME8EmbeddedApplication1.java
. Follow these steps:
ME8EmbeddedApplication1.java
file in the Projects window.package me8embeddedapplication1; import jdk.dio.DeviceManager; import jdk.dio.UnavailableDeviceException; import jdk.dio.gpio.GPIOPin; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.microedition.midlet.*; public class ME8EmbeddedApplication1 extends MIDlet { @Override public void startApp() { try { GPIOPin pin = (GPIOPin)DeviceManager.open(2); boolean b = pin.getValue(); } catch (UnavailableDeviceException ex) { } catch (IOException ex) { Logger.getLogger(ME8EmbeddedApplication1.class.getName()).log( Level.SEVERE, null, ex); } } public void pauseApp() { } public void destroyApp(boolean unconditional) { } }
ME8EmbeddedApplication1
project by clicking on the hammer-and-broom icon in the NetBeans toolbar or by selecting Run then Clean and Build Project (ME8EmbeddedApplication1).ME8EmbeddedApplication1
project by selecting the green right-arrow icon in the NetBeans toolbar or by selecting Run then Run Project (ME8EmbeddedApplication1).
When the run is successful, the EmbeddedExternalDevice1 emulator starts with the ME8EmbeddedApplication1
suite running.
Follow these steps to debug an IMlet using NetBeans:
The debugger connects to the debug agent on the board and the program stops at your breakpoint.
Applications that require access to Device I/O APIs must request appropriate permissions in JAD files. For more information about using the Device I/O APIs, see the Device I/O API 1.1 specification at:
The JAD file must have the proper API permissions. Follow these steps to sign the application both in NetBeans and without an IDE:
jdk.dio.DeviceMgmtPermission
API, as shown in Figure 2-6.Figure 2-6 Adding API Permissions with NetBeans
[画像:Description of Figure 2-6 follows]MIDlet-Permission-1: jdk.dio.DeviceMgmtPermission "*:*" "open"
The NetBeans IDE enables developers both to sign the applications with a local certificate and upload the certificate on the device. Follow these steps:
Figure 2-7 Signing Application JAR with NetBeans
[画像:Description of Figure 2-7 follows]Note:
The selected certificate must be uploaded on the device and associated with the security client.
Figure 2-8 Keystores Manager Window
[画像:Description of Figure 2-8 follows]Figure 2-9 Exporting Key on a Device
[画像:Description of Figure 2-9 follows]_policy.txt
file from the /appdb
directory of the Raspberry Pi board and add a section with the client name and a set of permissions. For more information about the policy file format, see the External Client Policy Format section in the Java ME Embedded Profile 8 specification.client Signed [C=US,O=manufacturer CA,OU=TCK,CN=thehost]
_policy.txt
file back to the /appdb
directory on the Raspberry Pi board.If you are not using the NetBeans IDE, then you can sign your application using the command line. Follow the instructions on how to set up a keystore with a local certificate that can be used to sign the applications:
keytool
that is shipped with the Oracle Java SE JDK.
keytool -genkey -v -alias mycert -keystore mykeystore.ks -storepass spass -keypass kpass -validity 360 -keyalg rsa -keysize 2048 -dname "CN=thehost"
This command generates 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. You can change both passwords as desired.
certs
directory from the Raspberry Pi board over to the desktop using an sftp
client or scp
command, change into the certs
directory, 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.3 distribution.
{mekeytool} -import -MEkeystore _main.ks -keystore mykeystore.ks -storepass spass -alias mycert -domain trusted
This command imports the information in mykeystore.ks
that you just created to the _main.ks
keystore. After this is completed, copy the certs
directory back to the Raspberry Pi board by using an sftp
client or scp
command.
jadtool -addcert -chainnum 1 -alias myalias -keystore mykeystore.ks -storepass spass -inputkad myjad.jad -outputjad myjad.jad
-useSha256
parameter. If not present, the default algorithm SHA1withRSA is used.jadtool -addjarsig -chainnum 1 -jarfile myjar.jar -alias myalias -keystore mykeystore.ks -storepass spass -keypass kpass -inputjad myjad.jad -outputjad myjad.jad -useSha256
This method allows you to bypass a certificate check and run unsigned applications as if they were signed and given all requested permissions. Use this method only for development and debugging. Perform final testing using a real certificate as described in method #1 or #2.
NullAuthenticationProvider
, set the following property in the jwc_properties.ini
file on the Raspberry Pi board:
[internal] authentication.provider = com.oracle.meep.security.NullAuthenticationProvider
jwc_properties.ini
file as follows:ams.verifier.requires_sha256 = true
There are two ways in Oracle Java ME 8.3 to obtain a device log:
These options are mutually exclusive because each of them requires the Developer Agent program but only one instance of the Developer Agent program can be run.
You can obtain Java Logs via an SDK Output Console window with or without using the NetBeans IDE.
If you want to use the NetBeans IDE, follow these steps:
Run the NetBeans IDE.
Select an IMlet in the Projects window and run it.
The NetBeans IDE opens the EmbeddedExternalDevice1 window.
Click the Output button. The log is available in the SDK EmbeddedExternalDevice1 Output Console window shown in Figure 2-10.
Figure 2-10 Java Logging Through the SDK Output Console Using NetBeans IDE
[画像:Description of Figure 2-10 follows]If you want to obtain Java Logs without using the NetBeans IDE, follow these steps:
bin
/device-manager.exe
.emulator.exe -Xjam -Xdevice:EmbeddedExternalDevice1
Figure 2-11 Java Logging Using the SDK Output Console
[画像:Description of Figure 2-11 follows]To obtain Java Logs using a console application such as Windows Command Line or Far, you must run the Developer Agent program manually. Follow these steps:
java -jar proxy.jar -socket <IP Address>
Figure 2-12 Java Logging Using a Console Application
[画像:Description of Figure 2-12 follows]You can control the scope of information being logged by editing the following parameters in the jwc_properties.ini
file:
Table 2-2 Logging Parameters
Parameter | Functional Area |
---|---|
|
The information storage subsystem. The generated messages are useful when facing issues with installing or running applications. |
|
The Record Management System. |
|
The security provisioning system. |
|
GCF |
|
The generated messages are useful when facing issues with installing or running applications. |
To select a level of logging details, set a parameter value as follows.
0 - all information messages
1 - warning level messages
2 - errors
3 - critical (system's functioning is not guaranteed)
4 - logging is turned off
This section provides helpful information for working with an embedded display. The section contains the following topics:
If two displays are connected to your board, you can set the primary display by editing the frame_buffer.device
property in the jwc_properties.ini
file. For more information about editing the jwc_properties.ini
file, see Configuring the Java Runtime Properties.
The name of the embedded display is available in Linux in the /dev
directory and has the form /dev/fb*
.
To access the embedded display in your applications, use the Display.getDisplays() method. The ID of the embedded display corresponds to the name of the device in Linux.
Scripting on this page enhances content navigation, but does not change the content in any way.