Oracle® Java ME Embedded Getting Started Guide for the Windows Platform Release 3.3 E35132-02 |
|
Previous |
Next |
Using the Eclipse integrated development environment, you can create and test embedded applications using a graphical development environment.
Note: The examples in this chapter use the Eclipse Indigo 3.7 platform. |
The Oracle Java ME SDK Plugins are the same for both the Indigo 3.7 and Juno 4.2 platforms.
To download the Oracle Java ME SDK Plugins file for Eclipse (oracle-jmesdk-3-3-rr-eclipse-plugins.zip
), go to the following location:
http://www.oracle.com/technetwork/java/javame/javamobile/download/sdk
In Eclipse, go to Help > Install New Software. This displays the Available Software screen, as shown in Figure 4-1.
Figure 4-1 The Eclipse Available Software Screen
Press the Add button. This displays the Add Repository window.
In the Add Repository window, press the Archive button to open a file browser.
In the file browser, select the Eclipse plugin file that you downloaded, as shown in Figure 4-2. Click Open to return to the previous dialog.
The Add Repository window appears as shown in Figure 4-3. Press OK.
Figure 4-3 The Add Repository Window with Eclipse Plugins
The category Java ME SDK Tools appears in the Name area. Check the box in front of Java ME SDK Tools and ME SDK Demos as shown in Figure 4-4. Click Next.
Figure 4-4 Selecting Oracle Java ME SDK Plugins
The installation details are displayed. Press Next. The items you checked are listed, as shown in Figure 4-5. Press Next again.
Figure 4-5 Eclipse Plugins Installation Details
Accept the terms of the license agreement and click Finish.
Check the Java ME SDK Tools Category and its subcategories and press the Next button to start the Add wizard.
Accept the terms of the license agreement and click Finish. The installation process starts.
When the installation process completes, restart Eclipse. The Eclipse Welcome Screen is displayed, as shown in Figure 4-6.
On Eclipse Juno 4.2, installing the Oracle Java ME SDK plugins requires the Eclipse Mobile Tools for Java (MTJ) toolkit. The MTJ is not bundled with Juno and must be installed manually, before installing the Eclipse plugins.
To install the Eclipse Mobile Tools for Java toolkit:
Go to Help > Install New Software.
In the “Work with” field, enter this URL: http://download.eclipse.org/releases/indigo
Click Add.
When the plugins are discovered, open the Mobile and Device Development Tools hierarchy and check Mobile Tools for Java Examples and Mobile Tools for Java SDK.
Uncheck the "Contact all update sites...." checkbox and click Next.
On the installation screen select all plugins and click Finish. Then click OK.
A Juno plugin named org.eclipse.jetty.server_<version>.jar
conflicts with the MTJ libraries when the plugin version is higher than 6.
If the org.eclipse.jetty.server
version is higher than 6 you must prevent it from loading by changing its name so the JAR file is not parsed. Locate the file in the \plugins
directory of your Juno installation and change the extension from .jar
to something else.
For example, change it to: org.eclipse.jetty.server_<version>.
old.
Note: Once you have installed the MTJ toolkit for Eclipse Juno 4.2, the procedure for installing the Oracle Java ME SDK plugins is the same as for Eclipse Indigo 3.7. See "Installing Plugins on Eclipse Indigo 3.7". |
To configure Eclipse, follow these steps:
Select Window > Open Perspective > Other and choose Java ME, as shown in Figure 4-7. Click OK.
Figure 4-7 Selecting Java ME for Configuration
Select Window > Preferences > and expand the Java ME node.
Select Device Management. The Device Management page displays a list of devices used by Oracle Java ME SDK projects, as shown in Figure 4-8.
Click the Manual Install... button, to the right of the Device Management screen.
In the Specify Search Directory field, enter or browse to the location of the Oracle Java ME SDK platform installation. For example:
C:\Java_ME_platform_SDK_3.3
Click OK. When the five default emulators are detected, make sure all the devices are checked, as shown in Figure 4-9, and click Finish.
Click OK to close the installation window.
This returns you to the Eclipse main window. The Oracle Java ME SDK is now ready to use.
In this section, you create a sample IMlet file, IMletDemo.java
, from the code provided in Example 4-1. This IMlet file is used in the next section, "Creating a New Oracle Java ME SDK Project in Eclipse."
Copy the code shown in Example 4-1 into a text file. Use Notepad rather than WordPad, to avoid any unneeded extra characters.
Name the file IMletDemo.java
and Save. Set the file aside for now.
Example 4-1 Code for the Sample IMletDemo.java Project in NetBeans
import javax.microedition.midlet.MIDlet; public class IMletDemo extends MIDlet { boolean bFirst = false; boolean loopFlag = true; public void startApp() { if (bFirst = false) { try { // Perform startup operations } catch (Exception ex) { ex.printStackTrace(); return; } bFirst = true; } else { System.out.println("IMlet Demo is already started..."); } // Start program here } public void pauseApp() { // Pause the application } public void destroyApp(boolean unconditional) { bFirst = false; // Close all resources that have been opened } }
Follow the steps below to create a new Oracle Java ME SDK project in the Eclipse IDE:
Choose the File >New >Project > Java ME > Midlet Project menu item and click Next, as shown in Figure 4-10.
When the Create a MIDlet Project window appears, enter a Project Name (for example, IMletDemo
).
To the right of the Configurations window, press the Add... button to add a configuration. This displays the Add Configuration dialog box, with no configurations, as shown in Figure 4-11.
Figure 4-11 Creating a New MIDlet Project
In the Add Configuration dialog box, select "Oracle Java(TM) Platform Micro Edition SDK 3.3" from the drop-down menu in the SDK field. In the Device field, select "IMPNGDevice1," as shown in Figure 4-12.
Press Finish. This displays the New MIDlet Project window again, with IMPNGDevice1
selected as the Active Configuration, as shown in Figure 4-12.
Figure 4-12 Creating a New Active Configuration
Press Next. This displays the MIDlet Project Content dialog box, as shown in Figure 4-13.
The MIDlet Project Content dialog box allows you to create an Application Descriptor for your new project.
In the MIDlet Project Content dialog box, set the following fields as shown here:
Microedition Configuration: Connected Limited Device Configuration (1.1)
Microedition Profile: Information Module Profile (NG)
Figure 4-13 Creating A New Application Descriptor
Press Finish to create the new IMletDemo
project.
Your new Eclipse project is ready to be run, as shown in Figure 4-14.
Figure 4-14 The New IMletDemo Project Overview
With the IMletDemo
project displayed in the Overview window of the Eclipse workscreen, do the following:
Click the Application Descriptor tab to display the contents of the Application Descriptor.
Change the MicroEdition-Profile
property to IMP-NG
, as shown in Figure 4-15.
Figure 4-15 Configuring the Application Descriptor
Click the Application Descriptor in the Pack window, as shown in Figure 4-16.
Press Control-S to save your changes.
Figure 4-16 Saving Changes to the Application Descriptor
Adding a Test MIDlet to Eclipse allows to you set up sample code, from which you can easily launch your own project. To add a test MIDlet to Eclipse:
Select File > New > Java ME MIDlet.
Enter the name and optional package of the MIDlet, as shown in Figure 4-17.
Press Finish. This creates the IMletDemo
test MIDlet and displays Eclipse default code, as shown in Figure 4-18.
Figure 4-18 Displaying the IMletDemo Test MIDlet Sample Code
You have just created a new Oracle Java ME Embedded project as a test MIDlet in Eclipse. At this point, you can use the skeleton code provided in "Creating a Sample IMlet File" to start building an embedded project.
Select and delete the default code displayed in your new Eclipse project window.
Copy and paste the sample code you created in "Creating a Sample IMlet File" into the Eclipse project window.
Select IMletDemo.java
in the Package Explorer window, as shown in Figure 4-19.
Press Control-S to save the new IMletDemo.java
code in the Eclipse workscreen.
Figure 4-20 shows the Eclipse IDE window with the new project sample code incorporated.
Figure 4-20 The IMletDemo Sample Project Code
To run the IMletDemo
sample code:
With IMletDemo.java
selected, as shown in Figure 4-19, press Control-F11.
This runs the sample code and launches the IMPNGDevice1 emulator, with the IMletDemo
MIDlet Suite running, as shown in Figure 4-21.
For more information on working with the Oracle Java ME SDK emulator, see Chapter 3.
Figure 4-21 The IMPNGDevice1 Emulator with the IMLetDemo Running