Skip Headers
NetBeans Developing Applications with NetBeans IDE
Release 8.0

E50452-06
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
PDF · Mobi · ePub

21 Developing Java ME Applications

This chapter describes how to create, test, debug, and deploy Java ME applications using NetBeans IDE.

This chapter contains the following sections:

21.1 About Developing Java ME Applications

The Java ME project development support for NetBeans enables you to create applications for mobile devices with the following features:

21.1.1 About Java ME Embedded and CLDC Applications

A JavaTM 2, Micro Edition platform (Java METM Platform), Mobile Edition Embedded Profile (MEEP) application is an application targeted for mobile devices such as mobile phones, PDAs, and two-way pagers. Such applications conform to both the Connected, Limited Device Configuration (CLDC) and MEEP.

A Java ME Embedded application, or "MIDlet Suite," typically consists of:

  • A Java Application Descriptor file. This file contains a predefined set of attributes (denoted by names that begin with MIDlet-) that allows Application Management Software to identify, retrieve, and install the MIDlets.

  • A Java Archive file that contains:

    • Java classes for each MIDlet in the suite.

    • Java classes shared between MIDlets.

    • Resource files used by the MIDlets (for example, image files).

    • A manifest file describing the JAR contents and specifying attributes used by the AMS to identify and install the MIDlet suite.

In the IDE, MIDlet Suites are managed as Java ME Embedded projects. Java ME Embedded projects are executed through an emulator platform, which simulates the execution of the application on a specific mobile device. Using project configurations and preprocessor code blocks, you can define conditions for multiple devices in a single set of code, enabling you test and produce MIDlet suites for each device.

21.2 Understanding Java Platform Manager

The Java Platform Manager is a tool for registering different versions of the Java Development Kit (JDK) and other Java tools that your programs depend on. The dialog box lists all of your registered JDKs and SDKs in the left pane. It also lists the JDK that the IDE is running on as the Default Platform.

You can open the dialog box by choosing Tools > Java Platforms.

Using the Java Platform Manager, you can:

Note:

Though NetBeans supports Java Micro Edition (ME) Connected Limited Device Configuration (CLDC) development, the IDE does not have a CLDC platform included in the installer that allows you to create applications for CLDC devices. For more information, see http://wiki.netbeans.org/JavaMESDKSupport.

21.3 Creating Java ME Projects

A project is a group of source files and the settings with which you build, run, and debug those source files. In the IDE, all Java development has to take place within a project. Within a Java ME Embedded project, you can create multiple project configurations that customize your MIDlet for different types of mobile devices.

When a project is created, the IDE:

The Java ME Embedded project structure is similar to that of standard NetBeans projects. There are differences, however, in the build and dist folders to accommodate the MEEP build process.

Logical View

The logical view of the project, shown in the Projects window, provides a hierarchy of sources and resources which reflects the type of project and its contents.

The Source Packages node encapsulates all the Java packages of the project. Right-clicking on the Source Package node and choosing New lets you add new file templates to your application.

Files View

When a project is created, the following folders are created under build (shown in the Files window):

21.3.1 How to Create a Java ME Embedded Application from a Template

The IDE manages applications in projects. To create a new application, you must first create and configure a new project. Use the New Project wizard or the project properties to create multiple configurations that enable you to simultaneously build and deploy your application to a range of platforms and devices.

With project templates, the IDE controls all aspects of how your application is built, run, and debugged. You set a project's source directory, classpath, emulator platform, and other project settings when creating the project and in the Project Properties dialog box.

NetBeans IDE comes with the following Java ME Embedded project template:

  • Embedded Application. A new Java ME Embedded application in a standard IDE project.

To create a new project:

  1. Choose File > New Project.

  2. Select the template for your project.

  3. Specify the name of the project and where to create it. The IDE creates the project folder in the specified location. Click Next.

  4. Specify the emulator platform for the project. The emulator platform determines the execution environment for your project.

  5. Click Finish to complete the wizard.

21.3.1.1 Creating Embedded Application

You open the New Java ME Embedded Application wizard by choosing File > New Project and selecting the Java ME Embedded Application project template from the Java ME Embedded category.

The IDE creates a new Java ME Embedded application in a standard IDE project. You can also generate a MIDlet in the project.

21.3.2 How to Add a MIDlet to a Project Configuration

To add a MIDlet to a Project Configuration:

  1. Open the MIDlets properties page by choosing File > <active project name> Properties.

  2. In the Project Properties dialog, select Application Descriptor > MIDlets.

    Note:

    If you are setting the MIDlet properties for a project configuration other than the default configuration, you must uncheck the Use Values from "DefaultConfiguration" checkbox at the top of the page.

  3. Click the Add button. This opens the Add MIDlet dialog. The dialog lists the MIDlets available in the project.

  4. Use the Add MIDlet dialog to enter a name, then select a MIDlet class from the dropdown menu. You can also choose an icon for the MIDlet from the MIDlet icon dropdown menu.

  5. Click OK to close the dialog. The MIDlet is listed in the table.

21.3.3 How to Add Push Registry Entries

The push registry allows MIDlets to be launched in response to an incoming network connection. When a MIDlet registers for push notifications, the device software is instructed to listen for incoming network connections and launch the MIDlet, if appropriate.

A MIDlet can register for push connections at runtime using static methods in javax.microedition.io.pushregistry, which would require the user to run the MIDlet manually when the device is turned on.

A more common approach is to register at installation using properties contained in the application descriptor (JAD) file. This approach allows the AMS to ensure that the MIDlet can be registered, and to cause the installation to fail if there are registration conflicts (for example, if another MIDlet is already registered for the same socket connection).

Each key designation is unique and of the form MIDlet-Push-<n>, where <n> begins at 1 and is incrementally increased with each registration. A MIDlet suite can have multiple push registrations.

Note:

Push registry configuration is only available for projects whose profile version is set to MDP 2.0.

To add Push Registry Entries:

  1. Choose File > <active project name> properties. This opens the Project Properties dialog.

  2. Select Push Registry from the left pane.

  3. In the Push Registry properties page, click Add to add a new MIDlet, and provide the following information in the Add Push Registry Entries dialog:

    • Class Name. The MIDlet's class name.

    • Sender IP. A valid sender that can launch the associated MIDlet. If the value is the wildcard (*), connections from any source are accepted. If datagram or socket connections are used, the value of Allowed Sender can be a numeric IP address.

    • Connection String. A connection string that identifies the connection protocol and port number.

A push registration key is automatically generated and shown as an attribute in the MIDlet suite's Java Application Descriptor (JAD) file. To view the JAD file, choose the Application Descriptor Property settings from the left pane.

Note:

To make use of the Push Registry, you must also have permission to access the Push Registry API, javax.microedition.io.PushRegistry. API permissions are handled in the API Permissions page of the Project Properties.

Each key designation is unique and of the form MIDlet-Push-<n>, where <n> begins at 1 and is incrementally increased with each registration. A MIDlet suite can have multiple push registrations.

For more information about using the push registry, see http://www.oracle.com/technetwork/systems/index-156665.html.

21.3.4 Adding API Permissions

If your MIDlet suite needs to access certain protected APIs (for example, network connections), the MEEP 8 security architecture requires that the connection grant permission for access. Required permissions are listed in the Java Application Descriptor (JAD) file with the attribute MIDlet-Permissions.

You can also define optional permissions to limit access to sensitive data or functionality with the attribute MIDlet-Permissions-Opt.

During MIDlet suite installation, the MEEP compares the permissions requested with the permissions in the destination protection domain. If the required permissions can not be granted, the application will not be installed.

During execution, if a required permission is denied, an exception is returned. If an optional permission is denied, the application might continue to function, although its functionality would be limited.

You can set the permission requests from the API Permissions page of the Project Properties.

To Add API Permissions:

  1. Choose File > <active project name> properties. This opens the Project Properties dialog.

  2. Select API Permissions from the left pane.

  3. Click the Add Button.

  4. Choose an API from the dropdown list or enter an API name in the combo box. Permissions have the same naming structure as a Java class. For instance, javax.microedition.io.Connector.http is the permission for the HTTP protocol.

  5. Click OK.

  6. In the API Permissions table, check the Required box if you want installation to fail in the event that permission cannot be granted.

For more information about API Permissions, see http://docs.oracle.com/javame/config/cldc/opt-pkgs/api/meep/api/index.html.

21.4 Customizing MIDlet Properties

You can add, edit, or delete the attributes of a MIDlet suite for the active project configuration, and determine the order in which MIDlets are shown in a MIDlet suite.

To add a MIDlet to a suite:

  1. Open the MIDlets properties page by choosing File > <active project name> Properties.

  2. In the Project Properties dialog, select Application Descriptor and the MIDlets tab.

  3. Click the Add button. This opens the Add MIDlet dialog. The dialog lists the MIDlets available in the project.

  4. Use the Add MIDlet dialog to enter a name, then select a MIDlet class from the dropdown menu. You can also choose an icon for the MIDlet from the MIDlet icon dropdown menu.

  5. Click OK to close the dialog. The MIDlet is listed in the table.

Note:

Any class added to the project that extends MIDlet (directly or indirectly) will be automatically be added to the Application Descriptor.

To edit a MIDlet in the suite:

  1. Open the MIDlets properties page by choosing File > <active project name> Properties.

  2. Under Categories, select Application Descriptor. Select the MIDlets tab.

  3. Select a midlet and click the Edit button. This opens the Edit MIDlet dialog.

  4. Use the Edit MIDlet dialog to edit the name, MIDlet class, and MIDlet icon.

To change the order in which a MIDlet is shown:

Select an attribute and click the Move Up or Move Down button.

21.4.1 How to Customize the Application Descriptor (JAD) Attributes

You can choose which attributes are included or excluded in your project configuration by choosing File > <active project name> properties. In the Project Properties dialog, select Attributes.

The Application Descriptor page enables you to add, edit, or remove the list of attributes that allow application management software to identify, retrieve, and install the MIDlets of a MIDlet suite.

To add, edit, or remove an attribute:

  1. Click the Add button. The Add Attributes dialog opens.

  2. Choose an attribute from the combo box. Then add a value for the attribute. Note that the list of available attributes is dependent upon the MEEP version supported by the project configuration, as set in the Platform properties. You can also add user-defined attributes by entering the attribute in the combo box.

Note:

To avoid errors in verification, make sure all required attributes have a defined value. Also, do not begin user-defined attribute keys with MIDlet- or MicroEdition-.

21.4.2 How to Customize MEEP Javadoc Settings

For each of your projects, you can produce a set of Javadoc HTML pages that describe the project's classes, inner classes, interfaces, constructors, methods, and fields. The Javadoc is constructed from the structure of your code and the Javadoc comments embedded in your code.

You open the Documenting page by choosing File > Project Properties (project name). In the Project Properties dialog, select Build > Documenting.

To set the javadoc generation properties:

  1. Choose File > Project Properties (project name).

  2. In the Project Properties dialog, select Build > Documenting.

For more information on generating Javadoc documentation, see http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html.

21.5 Building Java ME Embedded Applications

The development life cycle of applications for mobile devices that support the Java ME, CLDC, and MEEP technologies includes building Java ME Embedded applications.

The IDE builds its project infrastructure directly on top of Apache Ant, the leading build tool for Java applications. The IDE stores all of the information about your project in an Ant script, a properties file, and a few XML configuration files. This means that you can build and run your projects outside of the IDE exactly the same as inside the IDE.

To build a Java ME Embedded project:

Choose Build > Build Project.

To create JAR files for multiple devices at once:

Right-click on the project and choose Batch Build.

To view and customize the build options for a project configuration:

  1. Choose File > Project Properties (project name).

  2. Expand the Build node in the left pane and choose one of the following:

    • Compiling. Customize javac options for generating debugging information, optimizing the compilation, and reporting the use of deprecated APIs. You can also set encoding and the level of debugging for the //#debug and //#mdebug preprocessor directives.

    • Signing. Sign MIDlets and add or remove security keystores.

    • Obfuscating. Set the obfuscation level for the application.

    • Documenting. Manage the source code documentation for the application.

The active project configuration is listed in the Configuration drop down menu on the Platform panel of the Project Properties dialog.

21.5.1 How to Customize Compilation Options

You can set the build options in a project configuration by choosing File > <active project name> properties. In the Project Properties dialog, select Build > Compiling.

Click in the associated check box to enable the following options:

  • Generate Debugging Info. If checked, the compiler generates line numbers and source files information. This is the -g option in javac. If unchecked, no debugging information is generated (-g:none).

  • Compile with Optimization. If checked, the compiled application is optimized for execution. This is the -O option in javac. Optimizing can slow down compilation, produce larger class files, and make the program difficult to debug.

  • Report Uses of Deprecated APIs. If checked, the compiler lists each use or override of a deprecated member or class. This is the -deprecated option in javac. If unchecked, the compiler shows only the names of source files that use or override deprecated members or classes.

You can also set the default encoding used by the preprocessor and compiler in the encoding field. The default value is the default encoding used by your JVM and IDE.

The Debug Block Level drop-down menu sets the debug level for the //#debug and //#mdebug preprocessor directives. If you enter a unique value for the level (for example, debug_graphics), the preprocessor allows only debug blocks that exactly match the debug block (for this example, //#debug debug_graphics). All other debug blocks are commented out.

If you choose a pre-defined level from the drop-down menu, the preprocessor comments out debug blocks on lower levels, as defined by the following hierarchy:

  • fatal (most exclusive)

  • error

  • warn

  • info

  • debug (most inclusive)

For example, if you choose warn, all info and debug blocks will be commented out.

Note:

If you are setting the properties for a project configuration other than the default configuration (DefaultConfiguration), you must uncheck the Use Values from "DefaultConfiguration" checkbox at the top of the page to customize these options.

21.5.2 How to Add Libraries and Resources to a Java ME Embedded Project

Adding a group of class files to a project's classpath tells the IDE which classes the project should have access to during compilation and execution. Use the Libraries & Resources properties page to add or remove additional libraries, projects, or JAR and ZIP files to a classpath for a project configuration.

Note:

If you are setting the properties for a project configuration other than the default configuration (DefaultConfiguration), you must uncheck the Use Values from "DefaultConfiguration" checkbox at the top of the page to customize these options.

You can add the following item types to your project:

  • Project. The JAR file produced by another project, as well as the associated source files and Javadoc documentation. Adding this item to a class path sets up a dependency between the current project and the selected JAR.

  • Library. A collection of JAR files or folders with compiled classes, which can optionally have associated source files and Javadoc documentation.

  • JAR file. A JAR file somewhere on your system. Adding a JAR file creates a library entry named by the JAR and containing the JAR.

  • Folder. The root of a package or directory containing files. Adding a folder does not create a library entry.

To add a project, file, folder or library to the project's classpath:

  1. Choose File > <active project name> properties. This opens the Project Properties dialog.

  2. Expand Build > Libraries & Resources in the left pane.

  3. Click on the appropriate button to open a file chooser for that item type. Clicking the Add Library button opens the Library Manager, where you can add or edit library classes.

Note:

If a project has multiple distribution JAR files, all of the JARs appear in the Project Jar Files window. You will need to select the correct version of the JAR file to include with the project configuration.

21.5.3 How to Customize MEEP Build Filter Settings

Filtering settings determine the files and packages that are included in a JAR file for a specific project configuration.

To set the Filtering options:

  1. Choose File > <active project name> properties.

  2. In the Project Properties dialog, expand Build > Filtering.

  3. Using the Filtering Properties dialog, you can set the following options:

    • Use Default Ant Excludes. If checked, files that are defined by Ant to be excluded by default (version control files and folders) are excluded from the JAR file.

    • Exclude Test and Test Packages. If checked, tests and test packages are excluded from the JAR file.

To include or exclude an item from the build:

All items are included by default. Expand the nodes and uncheck the boxes next to the files or packages you want to exclude.

Note:

If you are setting the properties for a project configuration other than the default configuration (DefaultConfiguration), you must uncheck the Use Values from "DefaultConfiguration" checkbox at the top of the page to customize these options.

21.5.4 How to Obfuscate a MIDlet Suite

Performance and security are primary concerns for any application. Because the Java language was designed to be compiled into a platform-independent bytecode format, much of the information contained in the source code remains in the bytecode, making it easy to decompile or reverse-engineer a Java application. This format can also contribute to larger file sizes, and with the limited resources of mobile devices, every byte saved in a Java ME Embedded application counts towards mobility and performance.

Obfuscators use a variety of methods to transform compiled code. Code obfuscation techniques include stripping object code of its symbol tables, or altering the names of variables and identifiers. Obfuscated programs are not only more difficult to decompile or reverse-engineer, they are also frequently smaller in size, improving performance and mobility as well as security.

You can add additional obfuscation parameters in the Additional Obfuscation Settings window. The default obfuscator included with the IDE is ProGuard.

You can find more details about command parameters for this obfuscator at http://proguard.sourceforge.net/.

Obfuscators make it more difficult for your application to be decompiled or re-engineered. Depending on the methods used, obfuscation can also reduce the size of the compiled MIDlet suite, reducing the size of the application and improving performance.

To obfuscate a MIDlet suite:

  1. Choose File > <active project name> Properties.

  2. In the Project Properties dialog, select Build > Obfuscating.

  3. Use the Obfuscation lever to set the level of obfuscation for the suite. The Level Description window describes the impact each level has on the MIDlet.

  4. You can add additional obfuscation parameters in the Additional Obfuscation Settings window.

Note:

If you are setting the properties for a project configuration other than the default configuration (DefaultConfiguration), you must uncheck the Use Values from "DefaultConfiguration" checkbox at the top of the page to customize these options.

21.5.5 How to Customize the JAR and JAD Files in a Build

You can modify the names of the JAR and JAD files, and specify whether the JAR file is compressed.

To modify the JAR and JAD files:

  1. Choose File > <active project name> Properties.

  2. In the Project Properties dialog, select Build > Creating JAR.

  3. The Creating JAR page lets you set the following options:

    • JAD File Name. Name of the JAD file created by the project sources. The file name must have a .jad extension.

    • JAR File Name. Name of the JAR file created by the project sources. The file name must have a .jar extension.

    • Compress JAR. If checked, the JAR file is compressed.

    Note:

    If you are setting the properties for a project configuration other than the default configuration (DefaultConfiguration), you must uncheck the Use Values from "DefaultConfiguration" checkbox at the top of the page to customize these options.

21.6 Working with Security and MIDlet Signing

Signing a MIDlet suite allows MEEP devices to verify the integrity and origins of your MIDlet suite. MEEP devices use signing information to check an application's source and validity before allowing it to access protected APIs. To sign a MIDlet suite, you create a key pair:

Each certificate has a designated security domain. Once your MIDlet suite has been verified, it can access any of the protected APIs permitted by its security domain.

You can sign a MIDlet suite by:

You then have to export the certificate and set its security domain in each emulator.

For more information about Java ME security features, see http://www.oracle.com/technetwork/systems/index-156466.html.

21.6.1 How to Set Security through MIDlet Signing

Signing a MIDlet suite allows MEEP devices to verify the integrity and origins of your MIDlet suite. To sign a MIDlet suite, you use the Signing Properties page to assign or create a key pair:

  • A private key that is used to create a digital signature, or certificate.

  • A public key that can be used by anyone to verify the authenticity of the signature.

You can then export the key pair to the emulator platform you are using for testing.

To sign a MIDlet suite:

  1. Choose File > <active project name> Properties. In the Project Properties dialog, select Build > Signing.

  2. Check the Sign Distribution checkbox to enable signing.

  3. Choose a keystore from the Keystore dropdown menu.

    Note:

    To create a new keystore or key pair, click the Open Security Manager button.

  4. Choose an alias from the Alias keystore dropdown menu. The menu lists the available aliases for the selected keystore.

  5. If necessary, click the unlock buttons to make the keystore and alias available for use.

  6. Click the Export Key into Java ME SDK/Platform/Emulator button to export a key into the emulator platform you intend to use to test the MIDlet.

21.6.2 How to Add or Creating a Keystore

Signing a MIDlet suite allows MEEP devices to verify the integrity and origins of your MIDlet suite. To sign a MIDlet suite, you assign or create a key pair.

  • A private key that is used to create a digital signature, or certificate.

  • A public key that can be used by anyone to verify the authenticity of the signature.

Key pairs are stored in keystore (.ks) files.

To create a new keystore:

  1. Choose File > <active project name> Properties. In the Project Properties dialog, select Build > Signing.

  2. Click the Open Keystores Manager button. This opens the Keystores Manager dialog.

  3. Click the Add Keystore button.

  4. Choose the Create a New Keystore radio button and enter the following information:

    • Keystore Name. A legal filename with the extension .ks

    • Keystore Folder. Folder in your system where the keystore file will be saved.

    • Password. The password that can be used to unlock the keystore.

  5. Click OK to close the dialog. The new keystore is displayed in the Keystores window of the Keystores Manager.

To add an existing keystore:

  1. Choose File > <active project name> Properties. In the Project Properties dialog, select Build > Signing.

  2. Click the Open Keystores Manager button. This opens the Keystores Manager dialog.

  3. Click the Add Keystore button. This opens the Add Keystore dialog.

  4. Choose the Add Existing Keystore radio button.

  5. Click the browse button to navigate to the location of the keystore file you want to add.

  6. Click OK to close the dialog. The new keystore is displayed in the Keystores window of the Keystores Manager.

For more information about using keystores to sign your MIDlet suites, see http://www.oracle.com/technetwork/java/nbmp40-security-136005.html.

21.6.3 How to Create a New Key Pair

Signing a MIDlet suite allows MEEP devices to verify the integrity and origins of your MIDlet suite. To sign a MIDlet suite, you use the Signing Properties page to assign or create a key pair:

  • A private key that is used to create a digital signature, or certificate.

  • A public key that can be used by anyone to verify the authenticity of the signature.

You can then export the key pair to the emulator platform you are using for testing.

To create a new key pair:

  1. Choose File > <active project name> Properties. In the Project Properties dialog, select Build > Signing.

  2. Check the Sign Distribution checkbox to enable signing.

  3. Choose a keystore from the Keystore drop-down menu. The Security certificate details of the selected keystore:

    1. If no keystore is available, or you want to create a new keystore, click the Open Keystores Manager button. This opens the Keystores Manager dialog.

    2. Choose a keystore from the left window of the dialog, or click Add Keystore to create a new keystore. Then close the Keystores Manager.

  4. Choose an alias from the Alias keystore drop-down menu. The menu lists the available aliases for the selected keystore. You can create new aliases in the Keystores Manager dialog.

  5. If necessary, click the unlock buttons to make the keystore and alias available for use.

  6. Click the Export Key into Java ME SDK/Platform/Emulator button to export a key into the emulator platform you intend to use to test the MIDlet.

For more information about key pairs and keystores, see http://docs.oracle.com/javame/dev-tools/jme-sdk-3.0-win/html-helpset/z40001fb51614.html.

21.6.4 How to Export a Key to an Emulator Platform

To test a signed MIDlet in an emulator device, you must export the key and its corresponding certificate to the emulator platform.

To export a key:

  1. Choose File > <active project name> Properties.

  2. In the Project Properties dialog, select Build > Signing.

  3. Check the Sign Distribution checkbox.

  4. Select a Keystore and alias (a key pair).

  5. Click the Export Key into Java ME SDK/Platform/Emulator button.

  6. In the Export Key dialog:

    1. Select the emulator platform,

    2. Select the security domain,

    3. Click the Export button.

21.7 Working with Java ME Embedded Project Configurations

One of the most difficult aspects of developing applications for mobile devices is device fragmentation. The situation arises when vendor-specific, proprietary, or optional APIs are added to mobile devices to expand device functionality. Mobile devices often differ in a variety of attributes, such as screen size or color depth, and many support proprietary or optional APIs. These differences can require special code or project settings. To solve this problem, the IDE supports project configurations.

A project configuration enables you to define an execution environment for each device you want to run your application on. With project configurations and preprocessing, you can write a single application and create, customize, and deploy a separate distribution JAR for multiple devices.

You should create one configuration for each distribution JAR you plan to build for your project. For example, if you are planning to support three different screen sizes using two sets of vendor specific APIs, you should create six configurations.

Properties that are defined in a project configuration include:

21.7.1 How to Work with Java ME Embedded Project Configurations

The following steps outline the basic process of working with Java ME Embedded Project configurations:

  1. Create a project using the best template for your programming needs.

  2. Create Additional Configurations:

    In the Project Properties window, select the Platform category. Then click New.

  3. Customize the Configuration.

    Right-click the project node and choose Properties. Then select the Platform category and select the configuration you want to customize in the Configuration drop-down list. You can use the same settings as the default configuration, or you can add MIDlets, libraries, and other resource files, define push registry entries and API permissions, and create settings for obfuscation and security. All changes you make to the default configuration, other than to the Run options, propagate to all other configurations automatically. Any changes you make to a configuration other than the default configuration apply only to that non-default configuration.

  4. Run Configurations.

    1. Right-click the project node and chose Run.

    2. Activate a different configuration by selecting the project node and choosing Run > Set Project Configuration from the main menu. Then choose a different configuration and run the project again. You can also change the configuration of the selected project with the Configuration combo box in the main toolbar.

21.7.2 How to Customize Java ME Embedded Project Configurations

A project configuration defines the execution environment for a Java ME Embedded application that emulates a specific mobile device. You can define multiple project configurations for an application, then customize the properties of each configuration to match the specific devices for which you are programming. This enables you to test and debug your application for each device. You can then use project configurations to deploy a separate distribution JAR for one or all of your configurations.

You customize project configurations using the Project Properties dialog.

After a project containing multiple configurations is built, the build folder contains the build directory for DefaultConfiguration. Sub-directories in the dist folder contain the build and distribution files for each configuration in the project.

To configure settings for a Java ME Embedded project:

  1. Choose File > Project Properties (project name).

  2. Select the category in the left pane and modify the properties in the right pane.

21.7.2.1 Customizing Project Configurations

Properties that can be viewed or customized in a project configuration include:

  • emulator platform

  • specific emulator device

  • supported version of the Connected Limited Device Configuration (CLDC)

  • supported version of the Micro Edition Embedded Platform (MEEP)

  • supported optional packages and APIs

  • attributes listed in the JAD file

  • MIDlets included in the JAR

  • push registry entries

  • API permissions

  • build properties

  • libraries and resource files bundled in the project

  • file filtering

  • obfuscation level

  • JAD and JAR file names

  • signing

  • javadoc generation

  • deployment methods

To create a new configuration for a project:

  1. Open the Run category of the Project Properties window by right-clicking the project node in the Projects window and choosing Set Configuration > Customize.

  2. Click New to open the Create New Configuration dialog box.

  3. Type a name for the new configuration.

  4. Click OK to close the Create New Configuration dialog box.

  5. Select the Platform category in the left pane of the Project Properties window and modify properties of the new configuration.

  6. Click OK.

21.7.2.2 Customizing Platform Properties

You can set the Platform properties of a project configuration by choosing File > Project Properties (project name). In the Project Properties dialog, select Platform.

The Platform project properties pane enables you to choose an emulator platform that simulates a mobile device to which the application will be deployed. The properties shown are specific to the active project configuration, shown in the Project Configuration drop down menu of the dialog.

To change the active emulator platform:

Choose an installed emulator from the Java ME Platform drop down menu.

To add or remove an emulator platform:

Choose Tools > Java Platforms from the Main Toolbar, or click the Manage Platforms button in the Platform Properties dialog. This opens the Java Platform Manager, where you can add or remove the platform.

To set the version of CLDC or MEEP supported:

Choose the appropriate radio button for Configuration and Profile.

Note:

The configuration and profile versions supported depend upon the platform emulator and device selected.

To choose the optional packages and APIs supported by the emulator platform:

Check the appropriate check boxes in the Optional Packages pane of the Project Platform Properties dialog. The dialog lists all the packages provided by the selected emulator platform.

21.7.2.3 Customizing the Application Descriptor (JAD) Attributes

You can choose which attributes are included or excluded in your project configuration by choosing File > Project Properties (project name). In the Project Properties dialog, select the Application Descriptor category.

The Attributes tab enables you to add, edit, or remove the list of attributes that allow application management software to identify, retrieve, and install the MIDlets of a MIDlet suite or LIBlets.

To add, edit, or remove an attribute:

  1. Click the Add button. The Add Attribute dialog opens.

  2. Choose an attribute from the combo box. Then add a value for the attribute.

    Note:

    To avoid errors in verification, make sure all required attributes have a defined value. Also, do not begin user-defined attribute keys with MIDlet- or MicroEdition-

21.7.2.4 Adding MIDlets to a Project Configuration

To add an existing MIDlet:

  1. Right-click on a project and choose Properties.

  2. Select Application Descriptor from the Categories window and select the MIDlets tab in the right pane.

  3. Click the Add button.

  4. Fill in the Add MIDlet dialog and click OK. The MIDlet is automatically added to the Application Descriptor (JAD) file.

To add a new MIDlet:

  1. Select a project and choose File >New File (Ctrl+N).

  2. Select Java ME Embedded under Categories, then select the MIDlet file template under File Types.

  3. Enter the appropriate information in the New MIDlet wizard.

  4. Click Finish.

    The MIDlet is automatically added to the JAD file.

21.7.2.5 Customizing Compilation Options

You can set the build options in a project configuration by choosing File > Project Properties (project name). In the Project Properties dialog, select Build > Compiling.

For more information on compiler options, see: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html

Click in the associated check box to enable the following options:

  • Generate Debugging Info. If checked, the compiler generates line numbers and source files information. This is the -g option in javac. If unchecked, no debugging information is generated (-g:none).

  • Report Uses of Deprecated APIs. If checked, the compiler lists each use or override of a deprecated member or class. This is the -deprecated option in javac. If unchecked, the compiler shows only the names of source files that use or override deprecated members or classes.

  • Track Java Dependencies. If checked, the latest version of any project dependencies is used by the IDE every time you build or run your project.

  • Enable Annotation Processing. If checked, annotation processing is enabled when your project is built.

21.7.2.6 Adding Libraries and Resources to a Java ME Embedded Project

Adding a group of class files to a project's classpath tells the IDE which classes the project should have access to during compilation and execution. Use the Libraries properties page to add or remove additional libraries, projects, or JAR and ZIP files to a classpath for a project configuration.

You can add the following item types to your project:

  • Project. The JAR file produced by another project, as well as the associated source files and Javadoc documentation. Adding this item to a class path sets up a dependency between the current project and the selected JAR.

  • Library. A collection of JAR files or folders with compiled classes, which can optionally have associated source files and Javadoc documentation.

  • JAR file. A JAR file somewhere on your system. Adding a JAR file creates a library entry named by the JAR and containing the JAR.

  • Folder. The root of a package or directory containing files. Adding a folder does not create a library entry.

To add a project, file, folder or library to the project's classpath:

  1. Choose File > Project Properties (project name).

    This opens the Project Properties dialog.

  2. Select Libraries in the left pane.

  3. Click the appropriate button (for example, Add Project) to open a file chooser for that item type.

    Clicking the Add Library button opens the Add Library dialog, where you can add or edit library classes.

21.8 Running Java ME Embedded Applications

When you run a Java ME Embedded application, the IDE compiles and builds the application according to the settings of the current. As the MIDlet executes, the output is shown in the device emulator. You can run any individual project that contains an executable class.

To run a project:

Choose Run > Run Project or right-click any project in the Projects window and choose Run.

You can also choose to execute the MIDlet using Over-the-Air provisioning which is the process of deploying an application from a website on to a mobile device. If you choose Execute Through OTA in the Java ME Embedded Project Run Property sheet, the IDE simulates the OTA process so you can test and demonstrate the full provisioning process of the MIDlet suites from the server to a device. Additional information on OTA Application Provisioning is available at http://www.oracle.com/technetwork/systems/index-156355.html.

21.8.1 How to Customize Java ME Embedded Project Run Options

You can choose one of two different ways to execute a Java ME Embedded program:

  • Regular Execution. Runs the project on an emulator device. In this mode, you can also set a security domain for the application, to test its security.

  • Execute Through OTA. Runs the project using Over-The-Air provisioning, which simulates the process of deploying an application from a server to a mobile device.

To customize the run options:

  1. Choose File > <active project name> Properties. In the Project Properties dialog, select Running.

  2. Click a radio button to choose between the two run options.

The MEEP specification includes the Over The Air User Initiated Provisioning Specification, which describes how MIDlet suites can be transferred over-the-air (OTA) to a device.

21.8.2 How to Run a MIDlet Suite with OTA Provisioning

Running your MIDlet suite with Over-The-Air (OTA) provisioning emulates the process that takes place when a device downloads and installs your suite from a server. If your suite is signed, the emulator gives it access to protected APIs according to the security domain of the suite's certificate. Running a suite with OTA provisioning also lets you test any inbound connections from the server as defined in the suite's push registry.

To enable OTA provisioning for an emulator:

  1. Choose File > <active project name> Properties.

  2. In the Project Properties dialog, select Running.

  3. Choose the Execute Through OTA radio button.

    The IDE enables OTA provisioning for the emulator and runs the MIDlet suite with the specified preferences.

Note:

If you are setting the properties for a project configuration other than the default configuration (DefaultConfiguration), you must uncheck the Use Values from "DefaultConfiguration" checkbox at the top of the page to customize these options.

21.8.3 How to Run Headless Builds

Headless builds for mobility projects are handled under the same principles as standard MEEP projects. If the project has already been opened in the IDE on a target computer and no reference problems exist, then any Ant target can be invoked from within the project directory.

To invoke the Ant target:

Type ant jar run at the command line.

21.9 Using Java ME Emulator Platforms

An emulator platform simulates the execution of an application on one or more target devices. For example, the Java ME SDK enables you to run applications on several example devices, or "skins" included with the emulator. An emulator allows you to understand the user experience for an application on a particular device, and to test the portability of the application across different devices.

In the IDE, you specify the emulator platform as part of the overall project configuration. Many emulator platforms are packaged as software developer kits (SDKs) from manufacturers of mobile devices.

Some of the differences between emulators include their support for:

Note that having an emulator does not completely free you from testing on your target devices. An emulator can only approximate a device's user interface, functionality, and performance. For example, an emulator might not simulate processing speed, so an application may run faster or slower on a target device than it does on an emulator.

21.9.1 How to Add MEEP Emulator Platforms

Adding an emulator platform to the IDE enables you to create project configuration and use that platform for compilation, execution and debugging within the IDE. Through the Java Platform Manager, you can add both custom and UEI-compliant emulator platforms.

Unified Emulator Interface (UEI) is a common set of standards specifying command-line access to emulator functionality. The UEI allows IDE manufacturers to write to a single interface and, with little or no effort, be able to support emulators from many different companies.

To add a UEI-compliant MEEP emulator platform:

  1. Choose Tools > Java Platforms.

  2. Click the Add Platform button.

  3. Choose Java ME CLDC Platform Emulator.

    Click Next.

    The wizard searches your system and compiles a list of all available Java ME platforms. The wizard indicates which platforms:

    • have already been installed.

    • are available for installation. Indicated by a box with a check in it.

    • cannot be installed. Indicated in red. You might be able to install these platforms as custom (non-UEI) platforms.

    If the platform you want to install is not listed in the page, click on the Find More Java ME Platforms and navigate to the directory where the platform is installed.

  4. Put a check in the checkboxes of the platforms you want install.

    Click Next.

    The chosen platforms are installed.

To add a non-UEI-compliant emulator platform:

  1. Choose Tools > Java Platform Manager.

  2. Click the Add Platform button.

  3. Choose Custom Java ME CLDC Platform Emulator. Click Next.

  4. In the General Information page, specify the following information:

    • The directory where the platform is located.

    • Syntax for execution and debugger commands

  5. In the Bootstrap Libraries page, add any additional libraries used by the emulator.

  6. In the Sources & JavaDoc page, add any additional source files and Javadoc used by the emulator. Click Finish to add the emulator.

21.9.2 How to Customize Java ME Platform Properties

You can set the Platform properties of a project configuration by choosing File > Project Properties (project name). In the Project Properties dialog, select Platform.

The Platform project properties panel enables you to choose an emulator platform that simulates a mobile device to which the application will be deployed. The properties shown are specific to the active project configuration, shown in the Configuration drop down menu of the Platform panel.

To change the active emulator platform:

  • Choose an installed emulator from the Java ME Platform drop down menu.

To add or remove an emulator platform:

  • Choose Tools > Java Platform Manager from the main toolbar, or click the Manage Platforms button in the Platform Properties dialog.

    This opens the Java Platform Manager, where you can add or remove the platform.

To set the version of CLDC/MEEP supported:

  • Choose the appropriate radio button for Configuration and Profile.

    Note:

    The configuration and profile versions supported depend upon the platform emulator and device selected.

To choose the optional packages and APIs supported by the emulator platform:

  • Check the appropriate check boxes in the Optional Packages pane of the Project Platform Properties dialog. The dialog lists all the packages provided by the selected emulator platform.

21.9.3 How to Use the Java ME SDK

The Java Micro Edition SDK is a collection of tools and device emulators that support the development of Java applications that run on devices compliant with the Micro Edition Embedded Profile (MEEP) and Connected Limited Device Configuration (CLDC). These include a wide range of mobile phones, embedded systems, Blu-ray consoles and other devices.

NetBeans IDE does not come bundled with the Java ME SDK.

Java ME SDK is supported only on Windows OS.

For more information about the Java ME SDK, see http://www.oracle.com/technetwork/java/javame/javamobile/download/overview/index.html.

For more information about Java ME SDK support in NetBeans IDE, see http://wiki.netbeans.org/JavaMESDKSupport.