Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 3.3 for NetBeans on Windows
E24265-05
  Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

5 Creating and Editing Projects

A project is a group of files comprising a single application. Files include source files, resource files, XML configuration files, automatically generated Apache Ant build files, and a properties file.

When a project is created, the SDK performs these tasks:

Java ME SDK and NetBeans create their project infrastructure directly on top of Apache Ant. Java ME SDK projects can be opened and edited in NetBeans, and vice-versa. With the Ant infrastructure in place, you can build and run your projects within the SDK or from the command line.

The SDK provides two views of the project:

Project settings are controlled in the project Properties window. Typically, you right-click on an item or subitem in a tree (a project, a file, or a device) and select Properties.

5.1 Project Types

The MIDP/CLDC platform implements the Mobile Information Device Profile and Connected Limited Device Configuration (JSRs 118 and 139). As described in "IMP-NG," the IMP-NG platform is a type of CLDC platform.

The CDC platform is implemented to support Advanced Graphics and User Interface Optional Package for the J2ME Platform, Personal Basis Profile 1.1, and the Connected Device Configuration (JSRs 209, 217 and 218). The AGUI API combines the PBP API and a subset of Java Platform, Standard Edition (Java SE) Swing capabilities.

5.1.1 MIDP Projects

A MIDP application (a MIDlet), is deployed as a MIDlet suite. A MIDlet suite is distributed as a Java archive (JAR) file and a Java Application Descriptor (JAD) file.

The IMP-NG version of a MIDlet is an IMlet. However, because IMP-NG is a subset of CLDC you can write IMP-NG applications as MIDlets.

The JAR file includes the Java classes for each MIDlet in the suite, Java classes shared between MIDlets, resource files, and other supporting files. The JAR file also includes a manifest describing the JAR contents and specifying attributes the Application Management Software (AMS) uses to identify and install the MIDlet suite.

The JAD file contains attributes that allow the AMS to identify, retrieve, and install the MIDlets in a project. The SDK automatically creates JAD and JAR files when you build the project.

5.1.2 CDC Projects

The CDC platform is implemented to support Advanced Graphics and User Interface Optional Package for the J2ME Platform, Personal Basis Profile 1.1, and the Connected Device Configuration (JSRs 209, 217 and 218). The AGUI API combines the PBP API and a subset of Java Platform, Standard Edition (Java SE) Swing capabilities.

Oracle Java ME SDK version 3.3 supports CDC projects running as standalone applications. The CDC project structure and behavior are much the same as that of CLDC projects.


Note:

An Xlet cannot be run standalone. It depends upon an application manager to manage its life cycle (its state) and system services. Xlets are not supported in this release.


A standalone CDC project requires a main application class that includes a method named main() that handles class loading, object creation, and method execution. The application interacts directly with the Java Runtime Environment to manage its own life cycle and system resource needs. When the main() method exits, the standalone application terminates.

5.2 The Project Wizard

This section describes how to use the Project Wizard to create Java ME projects. The project provides a basic infrastructure for development. You provide source files, resource files, and project settings as needed. Most project properties can be edited later. For more on project properties, see Chapter 6, "Viewing and Editing Project Properties."

5.2.1 Create a MIDP Project

Follow these steps to create a MIDP project.

  1. Click the File menu and select New Project.

    The New Project wizard opens.

  2. In the New Project window, select the Java ME category, and the Mobile Application project type. Click Next.

  3. On the Name and Location page, specify a project name.

    Most of the form is auto-filled, but you can alter any of the editable fields.

    Checking Create Default Package and Main executable Class creates a sample package and main class for your application. Click Next.

  4. On the Default Platform Selection page, select the Oracle Java(TM) Platform Micro Edition SDK 3.3 platform.

    The platform determines which devices you see in the Device dropdown menu.

  5. Make a device selection.

    The selected device typically determines the Device Configuration. If more than one Device Profile is available, make a selection. Click Finish.

The new project is listed in the Projects pane.


Note:

You can make additional project configurations using project configuration templates from previously saved templates or from templates installed on the platform by clicking Next on the Default Platform Selection page.


5.2.2 Create an IMP-NG Project

The process for creating an IMP-NG project is almost the same as a CLDC project. There are just a few things to watch for.

  1. Click the File menu and select New Project.

    The New Project wizard opens.

  2. In the Choose Project window, select the Java ME category, and the Mobile Application project type. Click Next.

  3. On the Name and Location page, specify a project name. Most of the form is auto-filled, but you can alter any of the editable fields.

    Checking Create Default Package and Main executable Class creates a sample package and main class for your application. Click Next.

  4. On the Select Platform page, change the platform selection to Oracle Java(TM) Platform Micro Edition SDK 3.3. The platform determines which devices you see in the Device dropdown menu.

    Choose an IMPNG device, and choose a Device Profile.

    Click Finish.

  5. To run the new project follow the steps in "Running a Project."

5.2.3 Create a CDC Project

NetBeans provides a wizard for creating new projects quickly and easily. Most project properties can be edited later on.

  1. Click the File menu and select New Project.

    The New Project wizard opens.

  2. In the Categories window choose Java ME and in the Projects window choose CDC Application.

  3. On the Name and Location page, specify a project name. Most of the form is auto-filled, but you can alter any of the editable fields.

    Check the Create Main class option to insert a template of the class Main in your project. You can rename the class or accept the default name. Click Next.

  4. On the Select Platform page, change the platform selection to CDC Oracle Java(TM) Platform Micro Edition SDK 3.3. The platform determines which devices you see in the Device dropdown menu.

    Choose a CDC device and a Device Profile, then click Finish.

  5. To run the new project follow the steps in "Running a Project," except you can select your new project instead of a sample project.

5.2.4 Import a Legacy MIDP Project

If you created a project using the Sun Java Wireless Toolkit for CLDC on Windows or Linux you can import your MIDlets into Java ME SDK projects. You can also use this procedure to create a project based upon a legacy sample project.

  1. In the File menu, select New Project.

  2. In the New Project dialog box, be sure Java ME is selected and select Import Wireless Toolkit Project. Click Next.

  3. Specify the WTK project location.

    Use browse to open the directory containing the legacy project.

  4. Select a project and click Next.

  5. Provide the project name, location, and folder for the new project.

    The default name, project name and folder name are based on the name of the project you are importing. Click Next.

  6. Select the platform type, the default device, and the configuration and profile, if applicable. Click Finish.

    Your new project opens in the Projects window.

  7. If the legacy project used signing, you must configure the signing properties as described in "Managing Keystores and Key Pairs."

5.2.5 Import a Legacy CDC Project

If you created a project using the CDC Toolkit, you can import your applications into Java ME SDK projects. You can also use import to create a project based upon a sample project.


Note:

Standalone projects created in the CDC Toolkit can be imported. Xlets cannot be imported.


The CDC platform name for the Oracle Java ME SDK version 3.3 does not match the legacy platform name in the CDC Toolkit 1.0 and the CDC Mobility Pack. Consequently, you get a reference error when you import a legacy CDC project.


Note:

To avoid the reference error, create a platform with the legacy name, as described in "Create a Platform for Legacy CDC Projects." You only need to create the platform once.


  1. In the File menu, select New Project.

  2. In the New Project dialog box, be sure Java ME is selected and select Import CDC Toolkit Project. Click Next.

  3. Browse to select the project location.

    The wizard detects any applications in the legacy installation and displays their locations on disk. Select a project and click Next.

  4. Provide the Project Name, Location, and Folder for the new project. Note that the default name project name and folder name are based on the name of the project you are importing. Click Finish.

    The imported project opens in the Projects window.

    See "Create a Platform for Legacy CDC Projects" and "View Project Files."

5.3 Working With Projects

The logical view of the project, shown in the Projects window, provides a hierarchy of sources and resources. Right-click on the project node to see actions related to the project.

New. Opens a form to build a new object for the current project. The new object is placed in the project's file structure by default, but you can control the file name and location. The Other option in the New menu permits adding different types of files to the project. For a sample procedure, see "Generating Stub Files from WSDL Descriptors."

Build. Builds a distribution Java archive (JAR) file. Project properties control the build process as described in "Building a Project."

Clean & Build. Cleans, then builds a distribution JAR file.

Clean. Cleans the build files.

Generate Javadoc. See the online help topic Generating Javadoc Documentation.

Deploy. See the online help topic "Deploying Java ME Applications."

Batch Build..., Batch Clean & Build..., Batch Clean..., Batch Deploy... See the online help topic "About Java ME MIDP Projects."

Run. Runs the project with the default device, as specified on the Platform property page. See "Platform Selection."

Run With... Run the selected project with a device you choose. This option can override the default device specified in the project properties.

Debug. See the online help topic "Debugging Tasks: Quick Reference."

Profile. Attach the profiler to the selected project. See Chapter 9, "Profiling Applications."

Set as Main Project. Make the current project the new main project. Toolbar actions, such as clicking the green Run button, act upon the main project by default.

Unset as Main Project. This option is visible if the selected project is the main project.

Open Required Projects. Open any projects that the current project requires.

Close. Close the current project. Be sure that any processes are stopped, as closing a project might not stop the emulator.

5.4 View Project Files

The Files window displays a physical view of all project files. Right-click to view project properties or choose an action related to the project.

build. The output directory for the compiled classes listed below. This directory also contains manifest.mf, the manifest file that is added to the JAR file.

dist. The output directory of packaged build outputs (JAR files and JAD files). The dist directory also contains generated Javadoc documentation.

lib. Contains libraries you have added to the project. See "Adding Libraries and Resources."

nbproject. The directory that contains the project Ant script and other metadata. This directory contains the following files:

res. Resource files you have added to the project. See "Adding Libraries and Resources."

src. Project source files.

build.xml. The build script. This build script only contains an import statement that imports targets from nbproject/build-impl.xml. Use the build.xml to override targets from build-impl.xml or to create new targets.

See "Create a MIDP Project" and "Create a CDC Project."

5.5 Create a New MIDlet

To create a new MIDlet from the Files view, right-click a project and select New > MIDlet. With this form you can specify the name of the MIDlet and its location within the selected project.

MIDlet Name. The name that users see when the application runs on a device.

MIDlet Class Name. The name of the new MIDP class.

MIDlet Icon. The path to an icon associated with the MIDlet. Users see the icon when the application runs on a device.

Project. Displays the name of the project.

Package. Specifies the location of the MIDlet class in the package hierarchy. You can select an existing package from the drop down menu, or type in the name of a new package. The new package is created along with the class.

Created File. Displays the name and the location of the MIDlet in the system's hierarchy.

When the new MIDlet is created the SDK automatically adds it to the project's Application Descriptor File.

5.6 Add Files to a Project

For all projects, right-click to use the context menu to add files to a project. Using this method places files in the proper location in project source or resources.

To add a MIDlet, Java class, Java package, Java interface or Other files, right-click the project name or the Source Packages node, choose New, and select the file type.

To add files by format (Project, JAR, Folder, Library) right-click the Resources node and select a format. See "Adding Libraries and Resources."

It is possible to add files by copying them directly to the project directory but it is not recommended.

5.7 Search Project Files

To search a project's files, right-click on the project and select Find... . The Find in Files utility supports searching a project's file contents or file names. The search input fields supports simple text matching and regular expressions.

Containing Text. The string you are looking for. If File Name Patterns is empty, all files are searched.

File Name Patterns. The files you are searching in. If the Containing Text field is empty you get a listing of files that match the pattern.

The options Whole Words, Match Case, and Regular Expression further restrict the search. Regular Expression Constructs are fully explained in:

http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#sum

5.8 Debugging MIDP and IMP-NG Projects

Java ME Projects use standard NetBeans debugging utilities. Refer to the NetBeans help topic, Debugging Tasks: Quick Reference. This topic includes links to a variety of debugging procedures.

If you have an external device that runs a supported runtime you can perform on-device debugging. The device must be detected by the Device Selector, as described in "Adding an External Device."

For a sample scenario, see the Oracle® Java ME Embedded Getting Started Guide for the Windows Platform at:

http://docs.oracle.com/javame/embedded/embedded.html