Sei sulla pagina 1di 43

Use Eclipse to develop mobile applications for Nokia devices

Skill Level: Introductory Michael Juntao Yuan Author, Analyst, and Developer

18 Jan 2005 This tutorial shows how to develop J2ME applications for Nokia handsets using the Eclipse IDE and the Nokia Developer's Suite for J2ME.

Section 1. Before you start


About this tutorial
This tutorial demonstrates how to develop Java 2 Platform, Micro Edition (J2ME) applications for Nokia handsets using the Eclipse IDE and the Nokia Developer's Suite for J2ME. This tutorial is written for J2ME and Nokia developers who are interested in using the powerful Eclipse IDE to boost productivity. It also targets existing Java Eclipse developers who need a short path to get started in real-world mobile application development for Nokia devices. Although the Nokia Developer's Suite for J2ME primarily provides tools for Nokia handset developers, you can use it for generic J2ME application development for other devices as well. Basic knowledge of Eclipse and J2ME will help you complete the tasks described in this tutorial.

Prerequisites
To complete the tasks and run the sample code in this tutorial, you'll need to have the Eclipse IDE Version 2.1.x or 3.x installed. You'll also need to register a free user

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 1 of 43

developerWorks

ibm.com/developerWorks

account at Forum Nokia (http://www.forum.nokia.com/). I cover how to download and install the Nokia Developer's Suite for J2ME in the tutorial.

Section 2. Introduction to the technology


What is J2ME?
Java 2 Platform, Micro Edition (J2ME) is the Java platform that runs on small mobile devices. It supports the standard Java programming language and contains a subset of APIs from the Java 2 Platform, Standard Edition (J2SE) with the addition of device-specific APIs. The Mobile Information Device Profile (MIDP) is a flavor of J2ME that runs on mobile phones. Available on more than 250 million handsets, the MIDP is by far the most pervasive computing platform available today. This tutorial focuses on MIDP application development. For more information about J2ME and MIDP, see the "J2ME 101" series of tutorials published by IBM developerWorks (see Resources).

Eclipse and J2ME


The open source Eclipse IDE has became the development tool of choice for many Java developers. Out of the box, Eclipse provides superb support for key IDE features such as team collaboration, context-sensitive code editors, refactoring, unit testing, debugging, and project management. But more importantly, Eclipse supports an application platform that allows third-party vendors to build specialized tools (plug-ins) on top of it. For example, many Eclipse plug-ins are available to assist Java 2 Platform, Enterprise Edition (J2EE) application development, visual modeling, testing, code analysis, and much more. However, for mobile phone developers, the power of Eclipse has proven elusive until just recently. For a long time, the IBM WebSphere Studio Device Developer (Device Developer) has been the only Eclipse-based IDE that supports J2ME development. Device developer supports the J2ME implementation from IBM known as the WebSphere Micro Environment. Mobile phone developers need a low-cost Eclipse plug-in that supports real-device MIDP SDKs provided by handset manufacturers. Enter the Nokia Developer's Suite for J2ME.

The Nokia developer platforms

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 2 of 43

ibm.com/developerWorks

developerWorks

As the world's largest mobile phone manufacturer, Nokia produces dozens of handset models at any given time. For developers, it can be a very confusing landscape. It takes a lot of time to research the characteristics and programming environment available on each device. To make life easier for developers, Nokia designs its handsets around several developer platforms. Each developer platform contains devices that have similar physical characteristics (such as screen size and memory size), UI styles, lead software, and programming environments. The Nokia Series 40 Developer Platform is for mass market devices such as the Nokia 7210 and 6230. It has by far the largest market share with 100 million Series 40 devices sold every year. The Nokia Series 60 Developer Platform is for Symbian-OS-based smartphone devices such as the Nokia 3650 and 6600. More than 10 million Series 60 devices are sold every year The Nokia Series 80 Developer Platform is for Symbian-OS-based high-end enterprise devices such as the Nokia 9500 and 9300 Communicators. The Nokia Series 90 Developer Platform is for Symbian-OS-based touch-screen multimedia devices such as the Nokia 7700 prototype device. There is currently no commercial device offered that uses the Series 90 platform. J2ME is supported on all Nokia developer platforms. The 2.0 version of the Series 40, 60, 80 and 90 platforms all support MIDP 2, the Wireless Messaging API, and the Mobile Multimedia API. They also provide optional support for the Bluetooth API, the Mobile 3D API, and the File I/O and PIM API.

The Nokia device SDKs


A device SDK contains the available Java API libraries as well the PC emulator for the particular device. The emulator replicates the characteristics and limitations of the physical device on the development PC. The SDK is a crucial tool for developing real-world device applications. Due to the rapid release cycle of new devices, it is impractical for Nokia to develop a separate SDK for each device. Instead, it only releases SDKs for representative devices. For example, the Nokia Series 40 Developer Platform 2.0 SDK is based on the Nokia 6230 device and it can be used to develop MIDP applications for Nokia 5140, 3220, and 6255 devices. It is the SDK that you will need in this tutorial. The Nokia Developer's Suite for J2ME provides a management interface for all the

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 3 of 43

developerWorks

ibm.com/developerWorks

SDKs installed on the development PC.

Section 3. Installation and configuration


Downloading the Nokia Developer's Suite 2.2 for J2ME
You can download a free Nokia Developer's Suite for J2ME from Forum Nokia's tool section at http://www.forum.nokia.com/tools. The Nokia Developer's Suite for J2ME Version 2.2 and higher supports Eclipse integration. On the download page, select the Request serial number for this product link to get a serial number e-mailed to the e-mail address you registered with your Forum Nokia account. You will need that number during installation.

Installing the Nokia Developer's Suite Version 2.2 for J2ME


Before you can run the downloaded installer, you must first uninstall any previous version of the Nokia Developer's Suite for J2ME. You will need to enter your Forum Nokia username and the serial number you requested (and received through e-mail). When prompted, you should select to integrate the suite with Eclipse. You eed to tell the installer the root directory of your Eclipse installation.

Starting Eclipse
Now, start the Eclipse IDE and you see a new Tools > Nokia Developer's Suite for J2ME menu item as well as a number of new icons on the tool bar. Figure 1. New menu in Eclipse

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 4 of 43

ibm.com/developerWorks

developerWorks

Downloading new SDKs


The Nokia Developer's Suite for J2ME comes with the following device SDKs: Series 40 Developer Platform 2.0 SDK V1.0 Series 60 MIDP Concept SDK beta 0.3.1, Nokia Edition The Series 40 SDK is used by default. You can download more device SDKs from Forum Nokia's tools section at http://www.forum.nokia.com/tool. You will need a separate serial number for each of those SDKs. The SDKs are typically installed in the C:\Nokia\Devices\ directory on a Windows PC.

Adding SDKs to the Nokia Developer's Suite


You might have to manually add the new SDKs into the Nokia Developer's Suite. To do this:

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 5 of 43

developerWorks

ibm.com/developerWorks

1. 2.

Select Tools > Nokia Developer's Suite for J2ME > Configure Emulators. Click Add to add new SDKs to the drop-down list. Figure 2. Add new SDKs

3.

Select the installation directory of the SDK to add it.


Trademarks Page 6 of 43

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

ibm.com/developerWorks

developerWorks

Figure 3. Select SDK installation directory

Configuring emulators
To configure the behavior of the device emulator: 1. 2. 3. Select Tools > Nokia Developer's Suite for J2ME > Configure emulators. Choose the emulator SDK from the drop-down list. Click Preference. You are able to set general properties of the emulator.

The Phone Number prefix field specifies the artificial phone number assigned to the emulator when the phone network environment is simulated. For example, the first instance of the emulator is assigned phone number "6230000" and the second instance is assigned "6230001". The two emulator instances can send SMS/MMS messages to each other using the phone numbers. Figure 4. General properties

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 7 of 43

developerWorks

ibm.com/developerWorks

The MIDP run-time properties such as the heap size and security domains are configurable too. Figure 5. Configure MIDP

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 8 of 43

ibm.com/developerWorks

developerWorks

The logging level of emulator can be specified in the MIDP Monitor tab. Here, you can also slow down the emulator's execution speed to emulate the slow CPU on devices on a fast PC. Figure 6. Logging level
Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved. Trademarks Page 9 of 43

developerWorks

ibm.com/developerWorks

You have installed the tools. Let's go through the entire process of building, testing, and deploying an MIDP application using those tools.

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 10 of 43

ibm.com/developerWorks

developerWorks

Section 4. Setting up the project


Starting a new project
To start a new project: 1. 2. Select New > Project. Choose the Nokia J2ME project type. Figure 7. Choose project type

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 11 of 43

developerWorks

ibm.com/developerWorks

3.

Specify a name and a root directory for the project. Figure 8. Create project name

4.

Choose an SDK to develop against if multiple SDKs are available. Figure 9. Select an SDK

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 12 of 43

ibm.com/developerWorks

developerWorks

Configuring the project paths


You can specify where to put the Java source files and the compiled class files in the project. Here, you just use the Eclipse default settings. Figure 10. Source folders on the build paths

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 13 of 43

developerWorks

ibm.com/developerWorks

By default, the project's classpath includes the J2ME API libraries in the SDK. You can add any external libraries into the classpath. Warning: If you do add external Java Archive (JAR) libraries that are not available on the physical device to the project, you must package them into the distribution JAR file manually. Otherwise, the MIDlet throws a "Class not found" exception when you deploy it on the device. Figure 11. Define the classpath

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 14 of 43

ibm.com/developerWorks

developerWorks

Viewing it in the Package Explorer


Now you have finished the project setup. The project name is displayed in the Project Explorer. The source code directory and the class libraries are one level below the project name. You can click to open the class library and browse its contents. The library includes J2ME API classes as well as Nokia's implementation classes. You can even examine individual classes by decompiling their interfaces in the Java editor.

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 15 of 43

developerWorks

ibm.com/developerWorks

Figure 12. Viewing in the Package Explorer

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 16 of 43

ibm.com/developerWorks

developerWorks

Section 5. Working with the source code


Eclipse's new class wizard
Although the Nokia plug-in provides a wizard for generating new classes in the Tools > Nokia Developer's Suite for J2ME, I prefer Eclipse's default wizard because it supports automatic code completion for the superclass and implemented interfaces. Figure 13. New class

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 17 of 43

developerWorks

ibm.com/developerWorks

The skeleton Java source code file generated from the wizard is as follows. Figure 14. Generated source code

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 18 of 43

ibm.com/developerWorks

developerWorks

The TutorialMidlet class


The TutorialMidlet class is the MIDlet class that provides the entry of execution for the application. The Java Runtime Environment (JRE) first instantiates this class and then calls its startApp() method to start the midlet. The destroyApp() method is called when the user terminates the application. The TutorialMidlet class controls and displays all the UI screens in the application. All the user-generated soft-key events (such as when a user presses a soft key) are handled by the TutorialMidlet class because it implements the CommandListener interface and attaches itself as the command listener for all screen objects. The UI event callback method is commandAction().
package tutorial;

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 19 of 43

developerWorks

ibm.com/developerWorks

import javax.microedition.lcdui.*; import javax.microedition.midlet.*; public class TutorialMidlet extends MIDlet implements CommandListener { Display display; Command greetCommand; Command exitCommand; Command clearCommand; Command backCommand; WelcomeScreen welcomeScreen; HelloScreen helloScreen; // instantiate the internal variables public TutorialMidlet () { display = Display.getDisplay(this); greetCommand = new Command ("Greet", Command.OK, 0); exitCommand = new Command ("Exit", Command.EXIT, 0); clearCommand = new Command ("Clear", Command.CANCEL, 1); backCommand = new Command ("Back", Command.SCREEN, 1); welcomeScreen = new WelcomeScreen (); welcomeScreen.addCommand (greetCommand); welcomeScreen.addCommand (clearCommand); welcomeScreen.setCommandListener (this); helloScreen = new HelloScreen (); helloScreen.addCommand (exitCommand); helloScreen.addCommand (backCommand); helloScreen.setCommandListener (this); } // Called when the MIDlet is started by the AMS protected void startApp () { display.setCurrent (welcomeScreen); } protected void pauseApp () { // Do nothing } protected void destroyApp (boolean unconditional) { notifyDestroyed (); } public void commandAction (Command c, Displayable d) { if (c == greetCommand) { String name = welcomeScreen.getName (); helloScreen.setName(name); display.setCurrent (helloScreen); } else if (c == clearCommand) { welcomeScreen.setName(""); display.setCurrent(welcomeScreen); } else if (c == backCommand) { display.setCurrent (welcomeScreen); } else if (c == exitCommand) { destroyApp (true); } } }

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 20 of 43

ibm.com/developerWorks

developerWorks

Real-time checking for errors


The TutorialMidlet class uses the WelcomeScreen and HelloScreen classes, which you have yet to type in. The advanced Java editor in Eclipse alerts you to this inconsistency by flagging the relevant parts of the code with red bars. If you place the mouse over the red line, the editor displays an explanation box informing you why it thinks this is an error. Real-time syntax checking allows developers to take advantage of the consistency checking capabilities of the Java compiler without actually waiting for the compiling to complete. Figure 15. Real-time error checking

If the Build automatically option in the Eclipse Project menu is selected, Eclipse tries to continuously build the project in the background whenever the project is
Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved. Trademarks Page 21 of 43

developerWorks

ibm.com/developerWorks

updated. In this case, the Package Explorer also shows the compiling errors detected in the building process. Figure 16. Automatic build errors

The WelcomeScreen class


The WelcomeScreen class extends the Form class to represent a screen that contains several high-level MIDP UI components. As you have seen, the soft-key commands and event handlers of the WelcomeScreen are added in the TutorialMidlet class. The data in the nameField UI component can be accessed from outside this class through JavaBeans-style getter and setter methods. The image used on the form is from an external PNG image file welcome.png. The file must reside in the midlet's run time classpath in order to be accessible.
package tutorial;

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 22 of 43

ibm.com/developerWorks

developerWorks

import javax.microedition.lcdui.*; public class WelcomeScreen extends Form { private TextField nameField; public WelcomeScreen () { super ("Welcome"); Image img; // Construct the image from the media file try { img = Image.createImage("/welcome.png"); } catch (Exception e) { e.printStackTrace (); img = null; } ImageItem imageItem = new ImageItem ("", img, ImageItem.LAYOUT_CENTER, "Welcome"); nameField = new TextField ("Please enter your name", "", 10, TextField.ANY); append (imageItem); append (nameField); } public void setName (String n) { nameField.setString (n); } public String getName () { return nameField.getString (); } }

The HelloScreen class


The HelloScreen class extends the Canvas class to represent a screen that needs to be rendered by the application itself. The paint() method redraws the entire screen and is called by the system whenever the screen needs updating. Again, the soft-key commands and event handlers of the HelloScreen are added in the TutorialMidlet class. The name string rendered on this screen is set through the setName() method before the screen is displayed. The image file hello.png must also reside in the midlet's run time classpath.
package tutorial; import javax.microedition.lcdui.*; public class HelloScreen extends Canvas { private int width, height; private String name; private Image img; public HelloScreen () { width = getWidth ();

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 23 of 43

developerWorks

ibm.com/developerWorks

height = getHeight (); name = "unknown"; // Construct the image from the media file try { img = Image.createImage("/hello.png"); } catch (Exception e) { e.printStackTrace (); img = null; } } public void setName (String n) { name = n; } // Paint the screen based on the name protected void paint (Graphics g) { g.setColor(0xffffff); g.fillRect(0, 0, width, height); g.setColor(0x000000); g.drawImage (img, width / 2, height / 4, Graphics.VCENTER | Graphics.HCENTER); g.setFont(Font.getFont( Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE)); g.drawString (name, width / 2, height * 3/4, Graphics.BASELINE | Graphics.HCENTER); } }

No more errors
With all the source code typed in, Eclipse shows no errors or inconsistency. You are ready to run the midlet! Figure 17. No errors; run the midlet

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 24 of 43

ibm.com/developerWorks

developerWorks

Section 6. Running the midlet


Copying the resource files
The WelcomeScreen and HelloScreen classes use two external image files. Those two files must reside in the midlet's run time classpath. Unfortunately, there is no easy way to access the run time classpath (the bin directory in the project) from within the Eclipse IDE; you have to copy the files from outside the IDE. Figure 18 shows the bin directory in Windows file explorer.

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 25 of 43

developerWorks

ibm.com/developerWorks

Figure 18. Copying the resource files

Running the midlet


To run a midlet in the emulator, you first select the target MIDlet class (in this case, the TutorialMidlet class) in the Package Explorer and then select Run > Run As > Nokia SDK. Figure 19. Run the midlet

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 26 of 43

ibm.com/developerWorks

developerWorks

Seeing the emulator in action


The emulator is started with a diagnostic window as specified in the configuration. Figure 20. Emulator starts with diagnostic window

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 27 of 43

developerWorks

ibm.com/developerWorks

The emulator responds to user input. Figure 21. Emulator responds to user input

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 28 of 43

ibm.com/developerWorks

developerWorks

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 29 of 43

developerWorks

ibm.com/developerWorks

Section 7. Debugging the midlet


Setting up the debugger
The Nokia device SDKs provide limited debugging capabilities. You can use Eclipse's built-in debugger to gather debugging information and interact with the SDK emulator. First you have to set up the debugger in the Windows > Preferences window. You should deselect all the suspend options and increase the debugger timeout to 20,000 milliseconds. Figure 22. Set up the debugger

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 30 of 43

ibm.com/developerWorks

developerWorks

Setting break points


Using the Eclipse Run menu, you can set break points or watch points at the cursor position in the source code editor. Because of a bug in the Nokia SDK, stepping into a method could crash the emulator, so you should only set method break points. Figure 23 shows a method break point as indicated by the green dot on the left of the editor. You also need to rebuild the application for the break point to take effect. Figure 23. Setting a break point

Running the debugger


You can now run the midlet in debugging mode using Run > Debug .... The

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 31 of 43

developerWorks

ibm.com/developerWorks

emulator starts normally, but when you hit the break point (such as pressing a soft key to invoke the command handler commandAction() method in this case), Eclipse changes its display from the Java perspective to the debugging perspective. It displays the call stack, the current break point, and values of variables in the stack. After reviewing those data, you can resume execution using the Run. Figure 24. The debugging perspective

Section 8. Packaging for Over-The-Air


Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved. Trademarks Page 32 of 43

ibm.com/developerWorks

developerWorks

Generating JAR and JAD files


To run the midlet on a real device, you must package it into a pair of JAR and JAR descriptor (JAD) files that comply with the J2ME Over-The-Air (OTA) application-provisioning specification. You can use the Tools > Nokia Developer's Suite for J2ME > New Application Package wizard to generate the JAR and JAD files. You can choose to generate a new pair or edit an existing pair. Figure 25. New JAR and JAD pair

Customizing the attributes


You can customize the midlet name, description, version number, and many other attributes, including user-defined attributes, in the JAD and JAR manifest files. You also have control over what classes and resource files are included in the JAR file. Figure 26. Edit JAR/JAD attributes

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 33 of 43

developerWorks

ibm.com/developerWorks

Previewing the JAR/JAD files


Click on Preview to preview the JAD and JAR manifest files. Figure 27. Preview JAR/JAD manifest files

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 34 of 43

ibm.com/developerWorks

developerWorks

Generating the files


Click on Generate to actually generate the JAD and JAR files. You can place the generated files in the project root directory. Figure 28. Generate the actual JAR/JAD files

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 35 of 43

developerWorks

ibm.com/developerWorks

Signing the package


Using the Tools > Nokia Developer's Suite for J2ME > Sign Application Package wizard, you can digitally sign a midlet for distribution. The wizard lets you import your own digital certificates. It adds digital signatures and related public-key certificates to the JAR manifest and JAD files. Figure 29. Signing the application package

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 36 of 43

ibm.com/developerWorks

developerWorks

Testing the package in the emulator


Using the Tools > Nokia Developer's Suite for J2ME > Start Emulators wizard, you can test run the JAD file in a device emulator. The JAR file is referred to in the JAD file. You can start multiple emulator instances for the same midlet. Each emulator instance has a different artificial phone number. Figure 30. Running the JAD file for test

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 37 of 43

developerWorks

ibm.com/developerWorks

Testing OTA in the emulator


Using the Tools > Nokia Developer's Suite for J2ME > Start Emulators wizard, you can also test OTA provisioning of the JAD and JAR files in a device emulator. Instead of running the JAD file directly, the emulator tries to install it from a URL and go through the security and permission checks as if it is an OTA midlet. Figure 31. Testing OTA provisioning of the JAR/JAD files

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 38 of 43

ibm.com/developerWorks

developerWorks

Section 9. Deploying the midlet


Deploying over a local network
With the JAR and JAD files in hand, you can push them to the phone over a serial connection or a bluetooth connection using the Tools > Nokia Developer's Suite for J2ME > Deployment wizard. The pushed application will be installed on the phone. Figure 32. Local network install of midlet

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 39 of 43

developerWorks

ibm.com/developerWorks

Deploying to an OTA server


In order to distribute the midlet to the general public outside of the local serial or bluetooth networks, you need to place the JAD and JAR files on a public OTA server so that any mobile user can download and install it over the wireless data network. The deployment wizard supports copying the files to the ISP that hosts the OTA server using FTP. It automatically generates a WML file that contains a link to the JAD file. When the mobile user accesses the WML page from his WML browser on the phone and clicks on the link, the phone will automatically be triggered to install the midlet. Figure 33. FTP the midlet to an OTA server

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 40 of 43

ibm.com/developerWorks

developerWorks

Section 10. Summary and resources


Summary
In this tutorial, I walked you through the process of downloading, installing, and configuring the Nokia Developer's Suite for J2ME as an Eclipse IDE plug-in. Then, I illustrated the steps to develop, test, and deploy a midlet application using the tool. After going through all the tasks in this tutorial, you should have a solid understanding of how the Nokia Developer's Suite for J2ME works with Eclipse and how to take advantage of key features of the two tools to boost productivity in J2ME application development.

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 41 of 43

developerWorks

ibm.com/developerWorks

Downloads
Description
Code sample Information about download methods

Name
wi-nokiaeclsource.zip

Size
39 KB

Download method
HTTP

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 42 of 43

ibm.com/developerWorks

developerWorks

Resources
Learn Stay current with developerWorks technical events and Webcasts. The J2ME 101 series of tutorials on IBM developerWorks is a good place to get started with J2ME and MIDP programming. The IBM WebSphere Studio Device Developer is another Eclipse-based commercial IDE that targets J2ME developers. Get products and technologies Build your next development project with IBM trial software, available for download directly from developerWorks. You can download the Eclipse IDE from the Eclipse web site. The web site also has documentation on how to use the IDE and how to develop plug-ins. Forum Nokia's tools section has the Nokia Developer's Suite 2.2 for J2ME and related device SDKs for free download. Discuss Participate in developerWorks blogs and get involved in the developerWorks community.

About the author


Michael Juntao Yuan Dr. Michael Juntao Yuan is an author, analyst, and developer for end-to-end mobile solutions. He has extensive experience with J2ME, J2EE, and .Net technologies. Michael has published more than 30 mobile-related articles on leading technical and academic journals. He is also the author of two books: Enterprise J2ME (Prentice Hall, 2003) and Developing Scalable Series 40 Applications (Addison-Wesley and Nokia, 2004). For technical questions or comments about the content of this tutorial, contact the author, Michael J. Yuan, at michael.yuan@enterprisej2me.com.

Use Eclipse to develop mobile applications for Nokia devices Copyright IBM Corporation 2005. All rights reserved.

Trademarks Page 43 of 43

Potrebbero piacerti anche