6 Java ME Embedded Application Projects in Eclipse IDE

An Integrated Development Environment (IDE) uses projects to combine source files and settings that are necessary to build, run, and debug applications. Without an IDE, there are a lot more manual actions required to manage all the files and settings.

The chapter contains the following topis:

Basic Information About Project Management in IDE

The development and configuration of an application in the IDE takes place in the context of a project. It is the highest level of organization for the application that you are developing.

When you create a project in an IDE, it generates an Ant script to build the application. Alternatively, IDEs also support Maven. For more information about Ant and Maven, see their respective official web sites:

For more information about NetBeans IDE projects, see Developing Applications with NetBeans IDE at

http://docs.oracle.com/cd/E50453_01/doc.80/e50452/toc.htm

For more information about Eclipse IDE projects, see Eclipse Documentation at

http://help.eclipse.org

NetBeans IDE includes various project types that are preconfigured for developing Java SE, JavaFX, Java ME, and many other types of applications. Each type includes template source files and settings that are specific to the development platform.

You can initially define some of the more important settings when the project is created. Other settings are preconfigured with default values, however, you can change them at any time.

Creating a Java ME Project in Eclipse IDE

Eclipse IDE with Mobile Tools for Java (MTJ) extensions includes a project type that is preconfigured for developing Java ME Embedded applications. The project defines settings that are specific to Java ME Embedded.

You can initially define some of the more important settings when the project is created. Other settings are preconfigured with default values, however, you can change them at any time.

To create a Java ME project in Eclipse IDE:

  1. Ensure that the Java ME perspective is active as follows:

    1. Open the Window menu, select Perspective, select Open Perspective, and then Other.

    2. In the Open Perspective window, select Java ME and click OK.

  2. On the File menu, select New and then Java ME Project.

  3. In the New Java ME Project dialog, specify initial settings as necessary. You can click Next and Back to navigate the wizard. When you are done, click Finish.

When you create a project in Eclipse IDE, you can view it in one of two ways:

  • The Package Explorer tab provides a logical view of the project

  • The Navigator tab provides a physical view of the project

To configure the settings of an existing project in Eclipse IDE, right-click the project on the Package Explorer tab, and select Properties.

Adding an IMlet to a Java ME Application Project

To add an IMlet to a Java ME Embedded Application project:

  1. Right-click the project on the Package Explorer tab, select New, then Java ME MIDlet.
  2. In the New Java ME MIDlet dialog, specify initial settings as necessary. You can click Next and Back to navigate the wizard. When you are done, click Finish.

To configure the settings of an existing project in Eclipse IDE, right-click the project on the Package Explorer tab, and select Properties.

Importing an Existing Project into Eclipse IDE

To import an existing project into Eclipse IDE:

  1. Open the File menu and select Import.
  2. In the list, expand the General node and select Existing Project into Workspace. Click Next.
  3. Select the root directory of the project or an archive if you previously saved your project into an archive.
  4. Select the project name in the list and click Finish.

To configure the settings of an existing project in Eclipse IDE, right-click the project on the Package Explorer tab, and select Properties.

Managing Java ME Project Device Configurations in Eclipse IDE

The Java ME Embedded platform included with Oracle Java ME SDK provides an emulation environment for Windows to run Java ME Embedded applications on an emulated device.

To manage the device configurations on which you want to run the project:

  1. Right-click the project on the Package Explorer tab, and select Properties.

  2. In the left pane of the Properties window, select the Java ME category.

The Configurations list contains a list of devices that are available to the project.

To add a device to the Configurations list:

  1. Click Add.
  2. Select the Java ME SDK platform and device that you want to add.
  3. Optional: Specify a name for the configuration. By default, the name of the device is used.
  4. Click Finish to add the configuration to the project.

To edit the configuration, select it in the list and click Edit. To remove a configuration from the project, select it in the list and click Remove.

Below the configuration list, you can specify names of generated JAR and JAD files.

Performing Code Validation for a Java ME Project in Eclipse IDE

Code validation is the process of checking that the source code of your application complies with standards and recommendations for Java ME. Clean sources can help you maintain your code base efficiently.

Code validation settings in Eclipse IDE are configured globally (for all projects), but you can also override some of the settings for a specific project. To configure global code validation settings for all projects in Eclipse IDE:

  1. Open the Window menu and select Preferences.

  2. In the left pane of the Preferences window, expand the Java ME category and select Code Validation.

  3. Select the language constructs that you would like to be warned about or that you want to ignore when compiling.

To configure project-specific code validation settings for an existing Java ME project in Eclipse IDE:

  1. Right-click the project on the Package Explorer tab, and select Properties.
  2. In the left pane of the Properties window, select the Code Validation category under Java ME.
  3. Select Enable project specific settings.
  4. Select the language constructs that you would like to be warned about or that you want to ignore when compiling.

Managing Java ME Project Libraries in Eclipse IDE

A project may depend on external libraries of classes and source files. These dependencies are added to the class path so that they can be accessed during compilation and included into the JAR file. The list of libraries defines the -classpath option of the javac Java compiler.

To manage these libraries for an existing Java ME project in Eclipse IDE:

  1. Right-click the project on the Package Explorer tab, and select Properties.

  2. In the left pane of the Properties window, select the Library category under Java ME.

  3. Select the libraries to be included from the list of available libraries.

Java ME Embedded applications may use LIBlets, which are a special type of shareable software components used at runtime. To add LIBlets to a Java ME project in Eclipse IDE:

  1. Right-click the project on the Package Explorer tab, and select Properties.
  2. In the left pane of the Properties window, expand the Java Build Path category and select LIBlets.
  3. Click Add and configure the LIBlets that you want to add to the project build path.

Obfuscating Java ME Embedded Applications in Eclipse IDE

Obfuscation refers to deliberately making program code harder to understand, decompile, and reverse-engineer. Obfuscators are programs that transform readable code into obfuscated code.

Oracle Java ME SDK includes ProGuard, which is a Java bytecode obfuscator. It first shrinks, optimizes, and preverifies Java class files to make them more compact. Then it transforms the bytecode to make it almost impossible to reverse-engineer. This is an important security measure, because raw bytecode produced by the Java compiler contains much of the source code information, which is your intellectual property. Size optimization is also crucial for Java ME Embedded applications, which are designed for resource-constrained devices.

Obfuscation settings in Eclipse IDE are configured globally (for all projects), but you can also override some of the settings for a specific project. To configure global obfuscation settings for all projects in Eclipse IDE:

  1. Open the Window menu and select Preferences.

  2. In the left pane of the Preferences window, expand the Java ME category, then expand Packaging, and select Obfuscation.

  3. If you want to set command-line options for running ProGuard, select Use specified arguments and enter the options in the field that follows the check box.

  4. You can use the Proguard Keep Expressions list to define the list of classes and class members to be preserved as entry points to the application. By default, all public classes that extend the javax.microedition.midlet.MIDlet class are preserved from obfuscation. Click Add to add more regular expressions to the list. Double-click existing expressions to modify them. Select an expression and click Remove to remove it from the list.

To configure project-specific obfuscation settings for an existing Java ME project in Eclipse IDE:

  1. Right-click the project on the Package Explorer tab, and select Properties.
  2. In the left pane of the Properties window, select the Obfuscation category under Java ME.
  3. Select Enable project specific settings.
  4. If you want to set command-line options for running ProGuard, select Use specified arguments and enter the options in the field that follows the check box.
  5. You can use the Proguard Keep Expressions list to define the list of classes and class members to be preserved as entry points to the application. By default, all public classes that extend the javax.microedition.midlet.MIDlet class are preserved from obfuscation. Click Add to add more regular expressions to the list. Double-click existing expressions to modify them. Select an expression and click Remove to remove it from the list.

For more information about command-line options of ProGuard, see the ProGuard Reference Card at

http://proguard.sourceforge.net/#manual/refcard.html

Setting Java ME Project Packaging Attributes in Eclipse IDE

Java ME Embedded applications are packaged into JAR files with corresponding descriptor JAD files. The manifest in the JAR and the JAD file contain attributes that describe the application.

Packaging settings in Eclipse IDE are configured globally (for all projects), but you can also override some of the settings for a specific project. To configure global packaging settings for all projects in Eclipse IDE:

  1. Open the Window menu and select Preferences.

  2. In the left pane of the Preferences window, expand the Java ME category and select Packaging.

  3. If you want the version to automatically increment every time you build a project, select Increment Version Automatically. This option sets the MIDlet-Version attribute (or LIBlet-Version if you are building a LIBlet).

  4. You can use the Excluded Manifest Entries list to define the list of attributes that should be excluded from the manifest. By default, the following attributes are excluded:

    • MIDlet-Jar-URL: Points to the location of the JAR file.

    • MIDlet-Jar-Size: Specifies the size of the JAR file.

    • LIBlet-Jar-URL: Points to the location of the JAR file.

    • LIBlet-Jar-Size: Specifies the size of the JAR file.

    Click Add to add more attributes to the list. Click existing attributes to modify them. Select an attribute and click Remove to remove it from the list.

To configure project-specific packaging attributes for an existing Java ME project in Eclipse IDE:

  1. Right-click the project on the Package Explorer tab, and select Properties.
  2. In the left pane of the Properties window, select the Packaging category under Java ME.
  3. Select Enable project specific settings.
  4. If you want the version to automatically increment every time you build the project, select Increment Version Automatically. This option sets the MIDlet-Version attribute (or LIBlet-Version if you are building a LIBlet).
  5. You can use the Excluded Manifest Entries list to define the list of attributes that should be excluded from the manifest. By default, the following attributes are excluded:
    • MIDlet-Jar-URL: Points to the location of the JAR file.

    • MIDlet-Jar-Size: Specifies the size of the JAR file.

    • LIBlet-Jar-URL: Points to the location of the JAR file.

    • LIBlet-Jar-Size: Specifies the size of the JAR file.

    Click Add to add more attributes to the list. Double-click existing attributes to modify them. Select an attribute and click Remove to remove it from the list.

Signing Java ME Embedded Applications in Eclipse IDE

Signing a Java ME Embedded application allows MEEP devices to verify the integrity and origin of the IMlet suite. Signing information is used to check an application's source and validity before allowing it to access certain protected APIs. The certificate that is used to sign your application designates a security domain that defines the permitted protected APIs.

You should sign your applications for security reasons, to protect them from being tampered by malicious third parties, and to increase their acceptance by distribution channels. Security aware vendors always have more credibility in the industry.

Signing in Eclipse IDE is configured globally (for all projects), but you can also override some of the settings for a specific project. To configure global signing settings for all projects in Eclipse IDE:

  1. Open the Window menu and select Preferences.

  2. In the left pane of the Preferences window, expand the Java ME category and select Signing.

  3. Specify the location of the key store.

  4. Select whether you want to enter the password when it is required or save it in the current Eclipse IDE workspace keyring.

  5. To create a new key pair in the specified key store, click Create New Key Pair to the right of the Key Aliases list.

    To remove a key pair from the key store, select it in the list and click Delete Entry.

    To import a certificate from a certificate authority (CA), click Import Certificate.

    To import a response to your certificate signing request (CSR), click Import CSR Response.

  6. If you do not want to use Java defaults, configure additional settings under Advanced Settings.

To configure project-specific signing settings for an existing Java ME project in Eclipse IDE:

  1. Right-click the project on the Package Explorer tab, and select Properties.
  2. In the left pane of the Properties window, select the Signing category under Java ME.
  3. Select Enable project specific settings.
  4. Specify the location of the key store.
  5. Select whether you want to enter the password when it is required, save it in the current Eclipse IDE workspace keyring, or save it as part of the project.
  6. To create a new key pair in the specified key store, click Create New Key Pair to the right of the Key Aliases list.

    To remove a key pair from the key store, select it in the list and click Delete Entry.

    To import a certificate from a certificate authority (CA), click Import Certificate.

    To import a response to your certificate signing request (CSR), click Import CSR Response.

  7. If you do not want to use Java defaults, configure additional settings under Advanced Settings.

About Ant, Gradle, and Maven Support

Oracle Java ME SDK supports export of a Java ME Embedded project to a standalone Ant, Gradle, or Maven project to enable further building of the Java ME Embedded project without use of an IDE.

The exported project contains the source code for the Java ME Embedded application, build scripts, and build configuration. Note that the exported project provides only building and cleaning capabilities.

Exporting Java ME Embedded Projects in Eclipse IDE

In Eclipse IDE, you can export a Java ME Embedded project to a standalone Ant, Gradle, or Maven project to enable further building of the Java ME Embedded project without use of an IDE.

To export a Java ME Embedded project to a standalone Ant, Gradle, or Maven project in Eclipse IDE:
  1. On the File menu, select Export .
    The Export window opens up.
  2. In the Export window, select the folder with the type of the project: Ant Project, Maven Project, or Gradle Project.
    The Generate Standalone <Type> Project window opens up.
  3. In the Destination Folder text field, specify the project location directory by browsing to it on your file system.
  4. In the Dependencies Location group, select a radio button to specify the location of Java ME libraries.
    Java ME libraries are necessary for building the Java ME Embedded application. With a remote repository chosen, the Java ME Embedded application can be built without Java ME SDK installed.
    • Select Locally installed Java ME SDK to enable building a Java ME application using Java ME SDK.
    • Select Remote Maven Repository to enable building a Java ME application without using Java ME SDK.
      • In the Repository URL text field, specify the URL for the Java ME libraries.

      • In the Maven ant tasks path text field, which is available only for the Ant project, specify the path to the Maven ant tasks.