当前页面: 开发资料首页 → Netbeans 专题 → Deploy and Run Java ME Applications using Sun Java Application Server
摘要: This Tech tip describes how to deploy and run a Java ME application using Sun Java Application server and over-the-air (OTA) provisioning. We will create a web application that's wrapped around the mobile application that we want to make accessible over the air. Then we will download the mobile application from the webserver and install the application on the mobile device.
Before you begin, you have to make sure you have all of the necessary software installed, and that your project is set up correctly.
Make sure the following software is installed on your computer:
Before you can deploy to the SJS Application Server, you have to register a local instance with the IDE. Note that if you installed the NetBeans IDE 5.0/SJS Application Server bundle, the local SJS Application Server is already registered automatically.
In this tech tip, I will use one of the sample Java ME application included in the IDE. You can use any of your own mobile applications instead.
When you built the project, the IDE created two new directories to store the executables in,
dist
and build
.
To prepare the VariousGames application to be deployed remotely, you need to
change the JAD file's MIDlet-Jar-URL
property to
specify the URL of the remote location of the MIDlet's JAR file.
Select Window > Files from the menu to open the Files window.
Open the VariousGames node. Note the dist
directory
contains two executables, VariousGames.jar
and VariousGames.jad
.
Double-click /dist/VariousGames.jad
to open it in the Editor.
Find the MIDlet-Jar-URL
line:
MIDlet-Jar-URL: VariousGames.jar
Change this line to reflect your MIDlet's JAR file's remote location.
The location is a URL consisting of your web server's address, the SJS port,
and your web application's root context path:
http://yourWebServerAddress:port/yourAppRootContextPath/yourApplicationName.jar
In my example, I want to name my web application MyGames, and my application server's port is 8164. So the correct line looks like this:
MIDlet-Jar-URL: http://127.0.0.1:8164/MyGames/VariousGames.jar
Create a new Web Application using the NetBeans New Project wizard.
Open the Files Window in the IDE and open the MyGames node.
The web
directory you see here is your web application's
root directory.
Next we want
copy the mobile application's JAD and JAR files to the web application's
root directory.
Locate the files VariousGames/dist/VariousGames.jad
and
VariousGames/dist/VariousGames.jar
and copy
both of them into MyGames/web/
directory.
In MyGames/web
, create or edit the existing index page
to contain a link to either the JAD file or
JAR file depending on which version of MIDP you use:
If the URL refers to a JAR file, the emulator's Application Management Software (AMS) will use that URL to download the JAR. If the URL refers to a JAD file, the AMS downloads the JAD, which contains the JAR's URL, and then uses that URL to download the JAR. Either way, the AMS begins installation as soon as download is complete.
It is important to mention that, even though the MIDP 2.0 specification does not require developers to provide a JAD file (the URL can point to the MIDlet suite directly), it does recommend providing one: This is because the JAD descriptor helps the AMS determine whether the device has sufficient resources for the application to be installed successfully, even before the download takes place.
Look at the following examples to see what the index page should be like.
Example index.html
<html>
<head>
<title>My Games - Download</title>
</head>
<body>
<a href="http://127.0.0.1:8164/MyGames/VariousGames.jad">My Games</a>
</body>
</html>
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML
1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head>
<meta forua="true" http-equiv="Cache-Control"
content="must-revalidate, no-store"/>
</head>
<template>
<do type="prev" label="Back">
<prev/>
</do>/
</template>
<card title="My Games - Download" id="main">
<p> Games:</p>
<p align="left">
<a href="http://127.0.0.1:8164/MyGames/VariousGames.jad">My Games</a></p>
</card>
</wml>
You do not need to add the MIME types for the JAD and the JAR because Sun Java Application Server includes them in its Default MIME Type Mappings.
In some devices, including those from Nokia and Siemens, the discovery application uses a WAP browser, but it can be a native application as well. In Sun Java Wireless Toolkit, the discovery application includes a basic HTML browser.
Return to the Projects Window. Build the web application and deploy the .war file to the the Sun Applications server.
Right-click on the Web Project and select Deploy from the context menu. Wait for the IDE to compile the application, build the MyGames.war file, start the web server (in case it is not running yet) and deploy the application.
Verify that the application was deployed correctly:
In your browser, type in the URL to the JAD file, e.g.
http://127.0.0.1:8164/MyGames/VariousGames.jad
If everythings correct,
the browser should display the JAR file or open a
dialog suggesting to save it to your local disk.
(You do not need to actually save the file to your disk.)
The Sun Java Wireless Toolkit 2.2 implements the device behavior during OTA provisioning. You can use the emulator to test and demonstrate the full provisioning process of MIDlet suites from a server to the device. All you need to do is launch the emulator's Application Management Software (AMS).
Start the emulator. To launch the emulator's Application Management Software (AMS), select Start > Programs > J2ME Wireless Toolkit 2.2 > OTA Provisioning from the Windows start menu. To use the emulator executable from the commandline, run
[WTK2.2-intallpath]\bin\emulator.exe -XjamThe emulator window pops open, but instead of running your MIDlet classes directly, the emulator displays the welcome screen of its AMS as shown in the screenshot.
In the emulator window, select Apps (visible at the bottom right of the display) to go to the main list of installed applications.
In the list of installed applications, select Install Application and press the Select button on the emulator. The emulator now prompts you for the URL location of the application you want to install.
In the URL field, enter the URL of your web application's index.html page.
In our example, you would type:
http://127.0.0.1:8164/MyGames/
Select Go from the emulator's menu to begin the
installation. The emulator connects to the URL,
downloads and reads the HTML document (index.html
),
parses the hyperlinks, and displays a list of MIDlets you can
download from this page.
In our example, VariousGames.jad is displayed on the emulator.
Select the JAD and select Install from the emulator's menu. When the emulator asks you for your confirmation, select Install again to confirm and complete the installation. The emulator will download and verify the application and tell you when it was successfully installed. You'll be returned to the emulator's list of installed applications, which now includes the application you just installed — games.
Once the application is installed, running it is simple. Just click the application from the list and select Launch from the menu.