Skip Headers
Oracle® Java Micro Edition Embedded Client Developer's Guide
Release 1.1.1
  Go To Table Of Contents


2 Compiling Your Application

This chapter describes compiling an application from the command line or integrated development environment (IDE).

This chapter includes these topics:

2.1 Compiling from the Command Line

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.

2.1.1 Prerequisites

Before compiling, JDK 6.0 must be installed on your development workstation. If you do not yet have it, follow the instructions in Section, "Installing the JDK." Installing the JDK

Follow these steps to install the JDK.

  1. Download JDK 6 update 45 from
    If you download a later JDK version, modify the next two steps accordingly.

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

  3. Run the installer with the following command:


2.1.2 Bytecode Requirements for CDC Applications

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.

2.1.3 Compiling an Application

  1. On the workstation, cd into the base directory where the source files are located.

  2. Compile with the command

    javac -source 1.4 -target 1.4 helloworld/

    The class file HelloWorld.class will be created in the helloworld directory


    The value 1.4 must be assigned to the options -source and -target to ensure that the compiled byte codes are compatible with CDC.

2.1.4 Setting Environment Variables

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

You need to set the environment variable CVM_HOME to:


Where InstallDir is the directory on your Linux workstation where you installed the Oracle Java ME Embedded Client. PATH

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

  1. Edit either of the files ~/.bashrc or ~/.bash_profile.

  2. Append the following lines:

    export JAVA_HOME=/home/myname/tools/jdkVersion

    export PATH=/home/myname/bin:$PATH/tools/jdkVersion

  3. Log out of your Linux account and log back in.

  4. Use the following command to verify that javac can be found:

    which java


You can avoid setting the PATH on the target device by entering the relative path or full path to the cvm executable on the command line.

2.1.5 Running an Application on the Target Device

  1. 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 ftp or scp.

  2. From the workstation, open a terminal window that connects to the target device using a protocol such as ssh or telnet.

  3. Change directory to that containing the cvm executable with the command

    cd cvm_install_dir/bin

    where cvm_install_dir is the location where Oracle Java ME Embedded Client was installed on the device.

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

  5. Check the terminal output to validate the result.

2.2 Compiling in an IDE

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.

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

    Description of Figure 2-1 follows
    Description of "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

    Description of Figure 2-2 follows
    Description of "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

Description of Figure 2-3 follows
Description of "Figure 2-3 Selecting Java 1.4 Encoding"

2.2.1 Setting bootclasspath in an IDE

It is advisable to set bootclasspath when working in an IDE.