Monday, April 18, 2011

Deploying Wireless Java Applications

Developers usually build, test, and evaluate an application on a platform similar to the one on which it will be deployed and run. Development of wireless Java applications is more challenging because they typically are developed on one platform (such as Solaris or MS Windows) but deployed on a totally different one (such as a cell phone or PDA). One consequence is that, while emulators enable developers to do some of their testing on the development platform, ultimately they must test and evaluate the application in the very different environment of a live wireless network.

The aim of this article is to show you the different ways you can download local and network applications to J2ME-enabled devices, for both testing and final deployment. After a brief review of wireless Java applications and their development life-cycle, the article shows you how to:

  • Deploy wireless applications remotely
  • Download local and remotely deployed applications
  • Download applications over the air

Wireless Java Applications

Wireless Java applications fall into two broad categories:

  • Local applications (also called stand-alone applications) perform all their operations on a handheld wireless device and need no access to external data sources through a wireless network. Examples include calculators and single-player games.
  • Network applications consist of some components running on a wireless device and others running on a network, and thus depend on access to external resources. An example would be an email application, with a client residing on a wireless phone that interacts with a Simple Mail Transfer Protocol (SMTP) server to send messages.

Although these two types of applications are different, they are deployed in the same way. The big difference shows up later: Local applications are easier to test than network applications. For example, a calculator application can run on a wireless phone even when it is not connected to any network, but an email client won't work without a connection to the SMTP server that actually transmits the messages.

Wireless Java Applications Development Lifecycle

The development life-cycle of MIDlets and other wireless Java applications comprises three steps:

  1. Write the application. Use your favorite wireless application development environment and tools to develop the application. My favorite is the J2ME Wireless Toolkit. It has a simple and intuitive user interface that makes it easy to start developing wireless applications. More importantly, it includes several emulators for testing your applications. (Some of what follows will assume you use this toolkit too. If you use another development environment, you'll have to adapt what you read here to that environment.) 
  2. Test the application in an emulation environment. Once the application compiles nicely, the best place to begin testing it is an emulator. The J2ME Wireless Toolkit comes with several, including Motorola i85s, PalmOS device, and RIM Blackberry. It is important to note, however, that these emulators do not simulate perfectly all of the features of the corresponding devices. They are merely skins with the appropriate dimensions, so the following step is crucial.
  3. Download the application to a physical device and test it. Once you are happy with the application's performance on one or more emulators, download it to a real device and test it there. If it's a network application, test it on a live wireless network to ensure that its performance is acceptable.

This article's focus is on that last step: deploying and testing the application on a physical device.

Deploying and Running Remote Applications

The J2ME Wireless Toolkit enables you to run your local wireless application from within the development environment; the JAD and JAR files are available on your own system (if you're using the J2ME Wireless Toolkit, in <toolkit>/apps/YourProject/bin). If you wish to market your wireless applications, however, you need to deploy them where users from all over the world can access them.

Remote Deployment

To deploy your wireless applications remotely:

  1. Upload your application files (JAD and JAR) to a remote web server. If your project is named games, for instance, upload the files: games.jad and games.jar from the bin directory of your project home (for example, <toolkit>/apps/games/bin). Note that the two files must end up in the same directory on the server.
  2. Reconfigure the web server so that it recognizes JAD and JAR files:
    • For the JAD file type, set the file extension to .jad and the MIME type to text/vnd.sun.j2me.app-descriptor.
    • For the JAR file type, set the file extension to .jar and the MIME type to application/java-archive.

    How you configure the web server depends on which one you're using. For example, if you're using Tomcat, make sure your web.xml file includes the following lines:

     <mime-mapping>    <extension>jad</extension>    <mime-type>text/vnd.sun.j2me.app-descriptor</mime-type> </mime-mapping> <mime-mapping>    <extension>jar</extension>    <mime-type>application/java-archive</mime-type> </mime-mapping> 

  3. Change your JAD file's MIDlet-Jar-URL property to specify the URL of your JAR file. For example, in the copy of games.jad you uploaded to the server, change...

    MIDlet-Jar-URL: games.jar

    ...to...

    MIDlet-Jar-URL: http://YourWebServerAddress:port/pathTo/games.jar

Running Remotely Deployed Applications

To see whether your application deployed correctly, open an ordinary web browser and enter the JAD file's URL. The J2ME Wireless Toolkit's default emulator should appear and the remotely deployed application should run in it.

J2ME-enabled devices (the Motorola/Nextel i85s, for example) include a Java Application Manager (JAM) responsible for downloading, installing, and configuring applications. The J2ME Wireless Toolkit includes a sample JAM you can run in the default emulator. To see how the user will download and manage your application, open a command prompt, change the current directory to <toolkit>/bin, and enter the command:

    emulator -Xjam

The emulator appears and you see the JAM's main screen. In version 1.0.4 of the toolkit, the main screen looks like this:

 
Figure 1: The J2ME Wireless Toolkit Java Application Manager's Main Screen

Select the Install soft button and you will be prompted for the application's URL, as shown in Figure 2. Enter the URL of a web page that contains a hyperlink to the application's JAD file.

 
Figure 2: Entering the URL for the Application's JAD File

Entering a long URL into a wireless phone is inconvenient. A faster and easier way to get started is to use a command in this form:

    emulator -Xjam:install=http://yourWebServerAddress:port/yourApp.jad

Without further entry, the JAM downloads the JAR file specified in the JAD file and installs the application. The next time you start the emulator, simply select the JAM's Menu button, then use the menu to run the application, remove it, or perform the other functions shown in Figure 3:

 
Figure 3: The JAM's Main Menu

It is important to note that this syntax allows you to install only one MIDlet at a time. Entering a URL allows you to view a web page that may contain several MIDlets you can choose from. As an example, consider the following HTML file (midlets.html) that contains links to three JAD files:

 <html> <head> <title>Midlets</title> </head>  <body>  Download midlets: <p> <a href="http://127.0.0.1:8080/games.jad">Games.jad</a> <p> <a href="/mobility/midp/articles/deploy/calc.jad">Calc.jad</a> <p> <a href="/mobility/midp/articles/deploy/browser.jad">Browser.jad</a>  Thank you.  </body> </html> 

It is important to note that the hyperlinks point to the application's JAD file. Now, enter the URL into the install window as shown in Figure 4. (The IP address 127.0.0.1 is equivalent to localhost.)

 
Figure 4: Entering a URL in the Install Window

The JAM reads the HTML doccument (midlets.html), parses the hyperlinks, and displays a list of MIDlets you can download:

 
Figure 5: Links to Downloadable MIDlets

Now you can select a MIDlet to download. The JAM reads the JAD file to discover whether the device is capable of handling the application. If so, it downloads and installs the JAR file specified in the JAD file. Once the games MIDlet is downloaded and installed, you will see a display similar to Figure 6. Note that games.jad is the MIDlet suite that comes with the J2ME Wireless Toolkit.

 
Figure 6: The MIDlet Suite of Games Downloaded and Installed

The JAM is smart enough to notify you if you try to install a MIDlet that's already on your device, as in FIgure 7. It will, however, allow you to download an updated version of the MIDlet.

 
Figure 7: Warning That MIDlet Is Already Installed

Deploying and Running Applications on Physical Devices

Deploying and running applications in an emulation environment is a very good way to test the logic and flow of your application generally, but you won't be certain it will satisfy users until you test it on a real physical device connected to a wireless network. Your application's performance may be stunning in the emulator, which has all the processing power and memory of your desktop machine at its command, but will it perform well on the handheld device, with its limited memory and processing power, low bandwidth, and other constraints?

To perform realistic tests you need a J2ME-enabled physical device, and a data cable to connect it to your desktop. For this article

I used a Motorola/Nextel i85s cell phone, available from Nextel, which offers several models and rate plans.

Deploying Local Applications

If you have a Motorola J2ME-enabled phone, you can download stand-alone applications using the Motorola Java Application Loader Lite (JAL Lite). Note that JAL Lite limits filename lengths to 16 characters, and expects an application's JAD and JAR files to be in the same directory.

Connect the phone to your desktop and start JAL Lite on your desktop. You'll see a window like the one in Figure 8:

 
Figure 8: Motorola JAL Lite

The application displays the MIDlets already installed on the device. To install a new application, click on the Connect button, then the Download button. The application loader lets you browse your hard disk and select a JAD file. As soon as you do, it begins downloading the application and displays a progress indicator as shown in Figure 9:

 
Figure 9: JAL Lite Downloading an Application to the Phone

Once the download is complete, click on the Disconnect button, and disconnect the phone from the data cable. When you browse through the Java applications available on the phone, you should see the application you just downloaded. Select it and you will be asked if you wish to install it. If you answer yes, the application will be installed and you can start using it. The application remains on the phone until you explicitly remove it.

Buying and Deploying Remote Applications

You can use JAL Lite and the data cable to download local applications to a wireless phone from your desktop, including freely available applications you first download to your desktop using HTTP or FTP. Many useful applications are accessible only if you use special tools, however, usually because developers and wireless carriers wish to charge people for downloading them. There are two ways to download remotely deployed applications:

  • Download your own remotely deployed applications: You can use the Motorola iDEN Java Application Loader to download local and remotely deployed applications, much as you use JAL Lite to download local applications. Motorola's iDEN web site provides detailed information on how to become a member of iDEN's Developer Program and start downloading.
  • Buy and download others' applications: Motorola and Nextel have a large database of wireless applications available for download. Some are free. Check out iDEN Update, a web-based service with a client-side download application – itself a free downloadable application! – that enables you to download new features, applications, and enhancements. You can browse the site, select features and applications you'd like, and update your phone over the Internet. You'll need the iDEN Update client software and an update data cable. A snapshot of the iDEN wireless marketplace appears in Figure 10:
 
Figure 10: Motorola iDEN Update 
(click for full size)

Downloading Applications Over The Air

For some time, wireless portals in Europe such as Midletcentral have allowed customers to download applications directly to their phones, over the air. Over-the-air provisioning of wireless applications (OTA) is finally available in North America. Nextel customers, for example, can download network-aware wireless applications without an update data cable.

OTA is the deployment of wireless Java applications (MIDlet suites) from the Internet to wireless devices over a wireless network. Users need not connect their devices to the desktop with a data cable or visit a service center to install or upgrade software. See Over The Air User Initiated Provisioning Recommended Practice for the Mobile Information Device Profile for details.

To take advantage of OTA, you must equip your handheld device with a mechanism to discover MIDlet suites available for download, using the device's browser (such as a WAP browser) or a resident application written specifically to identify downloadable MIDlet suites. 

The process of downloading MIDlets over the air is illustrated in Figure 11.

 
Figure 11: Over-the-Air Provisioning of MIDlets 
(click for full size)

Conclusion:

Many Java-enabled wireless devices are already out there, and the necessary wireless infrastructure is in place to begin deploying wireless applications. This article discussed several ways to deploy and test local and remote wireless Java applications.

To succeed in the wireless market, you need to develop relationships with other developers, device manufacturers, content developers, and wireless carriers. Several device manufacturers (such as Nokia) and wireless carriers (such as Nextel) offer developer programs that can help you market your dazzling wireless Java application.

0 comments: