|Oracle® Java Micro Edition Embedded Client Developer's Guide
This chapter describes compiling an application from the command line or integrated development environment (IDE).
This chapter includes these topics:
You need to compile your application on the development workstation (Linux) to create class files that can then be deployed to the target device. Simple shell scripts and command lines are presented in this section to illustrate simple compilation and compiling for debugging or profiling.
Before compiling, JDK 6.0 must be installed on your development workstation. If you do not yet have it, follow the instructions in Section 22.214.171.124, "Installing the JDK."
Follow these steps to install the JDK.
Download JDK 6 update 45 from
If you download a later JDK version, modify the next two steps accordingly.
Open a Linux terminal and cd into the directory where JDK 6 has been downloaded. After installation, the environment variable
JDK_INSTALL_DIR will be set to this directory.
Set file permissions to enable execution with the following command:
sudo chmod a+x jdk-6u45-linux-i586.bin
Run the installer with the following command:
An Oracle Java ME Embedded Client program must comply with the requirements of the Connected Device Configuration (CDC), version 1.1.2. The correct bytecode will be generated for CDC provided that you specify JDK 1.4 at the command line with both the -source and the -target options. Refer to Section 2.1.3, "Compiling an Application" for an example.
On the workstation, cd into the base directory where the source files are located.
Compile with the command
javac -source 1.4 -target 1.4 helloworld/HelloWorld.java
The class file
HelloWorld.class will be created in the
The value 1.4 must be assigned to the options -source and -target to ensure that the compiled byte codes are compatible with CDC.
You should make sure that these environment variables are set correctly before running a compiled program on either your development workstation or on the target device.
This section uses the bash shell. Make adjustments if you use a different shell.
You need to set the environment variable
Where InstallDir is the directory on your Linux workstation where you installed the Oracle Java ME Embedded Client.
PATH environment variable should be set to include the location of the
javac command. In these instructions,
Version stands for the JDK version you have installed, for example, 1.6.0_45.
Edit either of the files
Append the following lines:
Log out of your Linux account and log back in.
Use the following command to verify that javac can be found:
You can avoid setting the
Make sure the class file is accessible by the target host.
This is typically accomplished by mounting the base directory (where the source and class files are located) as an nfs file system on the device. Or, on devices with less capability, the class file can be copied to a suitable directory on the device with a command such as
From the workstation, open a terminal window that connects to the target device using a protocol such as ssh or telnet.
Change directory to that containing the
cvm executable with the command
where cvm_install_dir is the location where Oracle Java ME Embedded Client was installed on the device.
Run the program on the device with the command
./cvm -cp /home/myname/working/HelloWorld helloworld.HelloWorld
assuming the first argument is the working directory on the device containing the class file.
Check the terminal output to validate the result.
If you prefer to work within an IDE such as NetBeans or Eclipse, you can compile an Oracle Java ME Embedded Client application by setting the project type to Java application, and specifying options to make the compiler generate bytecodes compatible with Java 1.4. For NetBeans, this is illustrated in the following steps.
Create a new project in NetBeans. Choose the category Java and project type Java Application, as shown:
Figure 2-1 Create New java Application Project
The newly created project creates a default Main class program.
Figure 2-2 New Java Project in NetBeans
Since this is a CDC program, you must change the compiler options to generate JDK 1.4 bytecodes. Select your project in the Projects page and right-click to get the Project Properties dialog box.
Under Categories, choose the first item, "Sources." Near the bottom of the dialog, pull down the Source/Binary Format menu, and select JDK 1.4.
Figure 2-3 Selecting Java 1.4 Encoding