Toolkits
2.3.1.1 J2ME Wireless Toolkit 2.1 Overview
The J2ME Wireless Toolkit 2.1 provides basic tools for developers to create MIDP 2.0 applications. The Wireless Toolkit (WTK) was created by Sun to facilitate MIDP development. At the time of writing, the production release can be obtained free of charge from Sun's website (http://java.sun.com/products/j2mewtoolkit/download-2_1.html).
Amongst more advanced features, it provides the developer with the ability to compile, pre-verify and package MIDlet suites on the command line, as well as providing a simple GUI to manage MIDP application creation. The "Build" button on the KToolbar combines all the command line functionality described in Section 2.1.1.6, apart from packaging. The packaging command in the Projects menu provides this extra step. A handy interface for creating the JAD file is also supplied and accessed via the Settings button.
The J2ME WTK does not, however, provide a text editor or sophisticated debugging facilities, so users may find development a slightly cumbersome process. It does, however, remain a useful tool as it provides developers with device emulators and a development infrastructure and it captures system output and other debug information such as error messages (see Figure 2.6).
Versions of this tool are available for Windows and Unix-based systems. At the time of writing, the J2ME Wireless Toolkit 2.1 is available in production releases for the following operating systems:
• Microsoft Windows XP or Microsoft Windows 2000
• Microsoft Windows 98/NT (unsupported)
|
ISi! J2ME Wireless Toolkit |
JSJX] | |||||
|
File Edit |
Help | |||||
|
New Project . |
jg Open Project .. |
5 Build |
Ife Run |
1 ry ______________ 1 | ||
|
Wi Settings ■■■ |
3T uear «wonsoie | | |||||
|
J Device: beiaultColorFhone |
~Z3 | |||||
Create a new project or open on existing one
Create a new project or open on existing one
Figure 2.6 J2ME Wireless Toolkit.
• Red Hat Linux kernel 2.4.2-2. glibc version 2.2.2 (unsupported).
Also required for development is Java 2 SDK Standard Edition (J2SE SDK) of at least version 1.4 (this is available at the following location: http://java.sun.com/j2se/downloads.html).
Although support is only given for the more recent Windows platforms, this still represents a good opportunity for Java developers to test wireless applications on their favored development platforms.
The toolkit offers the developer support in the following development areas:
• OTA emulation
The toolkit takes the developer through the steps a user experiences when discovering and downloading an application to the device. The emulator displays JAD file information, which allows the end-user to decide whether to install locally or not. The application is then downloaded and verified by the emulator device and installed. The application is then run "locally".
• MIDlet signing
MIDlet signing is new to the MIDP environment. The toolkit allows a developer to browse for a J2SE keystore file (an SKS file) and use it to sign a MIDlet suite
• WMA emulation for SMS (and CBS broadcasts)
• new skins for QWERTY and media devices
• certificate management - an interface for the developer to manage security certificate files (CER files) and view the contents of J2ME keystore files (KS files)
• Push Registry emulation - this emulates a MIDlet's reaction to an inbound network connection or timer-based alarm; the registry is set up using the Push Registry tab within the Project > Settings dialog
• access to J2ME Web Services - the user can generate a stub connector to access J2ME Web Services from the toolbar; the user provides a Web Service Descriptor Language file (a WDSL file)
• monitoring for all protocols - HTTPS, socket, datagram, COMM, SSL, SMS/CBS
• compile-time and runtime selection of API extensions (WMA, MMAPI)
• switching between MMAPI and MIDP 2.0 Media API - this allows the developer to set the abilities of the underlying API implementation on the emulator device (some devices ship with the full MMAPI, so developers may wish to configure the emulator to reflect more powerful devices)
• new demos - demos such as the Mobile Media MIDlet (mmademo) and SMSDemo MIDlet allow the developer to gain an idea of how the toolkit handles SMS messaging between emulators within the same instance of the toolkit
• support for the ProGuard obfuscator
Obfuscation provides a level of protection against reverse engineering. It also reduces the final file size of MIDlet suites. This is very useful when most end-users will be downloading their MIDlets remotely over the air. Smaller files mean more efficient execution and less space taken up in the device. ProGuard provides software that performs the obfuscation. It is available, under General Public License, at http://proguard.sourceforge.net.
• memory and network monitoring (from v1.0) - this includes message filtering, sorting messages and viewing network traffic
Installation
To enable installation of the J2ME Wireless Toolkit 2.1, the host PC will need to have the Java 2 SDK 1.4.1 installed. Installation on the PC can be carried out as follows.
1. Execute the file j2me_wireless_toolkit-2_1-windows.exe which is available from the download areas on the Java Sun website (see above).
2. The user will be prompted to confirm the location of the Java Runtime Environment (Figure 2.7). Version 1.4.1 or higher is required. If this is not present, it should be installed before continuing with the installation of the toolkit.
3. The destination of the toolkit can then be chosen and confirmed (Figure 2.8). In this case we deviated from the default location. Note that, at least for the current Toolkit, this name cannot contain spaces.
4. The installation program then prompts for the confirmation of a Program Folder name (Figure 2.9). On Windows machines, this is the name of the folder as it appears on the Start menu. It may be desirable to enter a shorter name.
5. A dialog reviewing the installation details is displayed. Press Next to begin installation.
6. The installer will then display a dialog to tell the user that installation has been completed (Figure 2.10).
- Figure 2.7 J2ME Wireless Toolkit setup.
- Figure 2.8 Confirming location.
- Figure 2.9 Selecting a program folder.
Figure 2.10 Installation complete.
Figure 2.10 Installation complete.
2.3.1.2 Apache Ant
Overview
The Apache Ant project is a part of Apache's Jakarta project (http://jakarta. apache.org) and is a Java-based building tool distributed under the Apache license. It has been developed by the Java community and is described as "kind of like Make, but without the wrinkles". It can be obtained from the Apache Ant website (http://ant.apache.org/index. html). We are going to use it in conjunction with another tool, Antenna, which provides specific Ant tasks for building MIDP 1.0 and 2.0 applications. This is distributed under the GNU Lesser GPL and can be obtained from the SourceForge website (http://antenna.sourceforge.net).
It is a reasonably easy tool to use and, in a similar way to the Wireless Toolkit, it automates the compiling, pre-verifying and packaging of a MIDlet suite. The execution of an emulator can also be added on to the end of the XML configuration file for extra convenience. Whereas the KToolbar provides the developer with adequate tools for MIDlet creation, Ant gives the developer fine-grained control over how the MIDlet suite should be put together. The really great thing about Ant is that it comes fully integrated with Borland's JBuilder, Sun's ONE Studio and can also be integrated with other IDEs such as JCreator (www.jcreator.com), JEdit (www.jedit.org), and Eclipse (www.eclipse.org). However, this section will look at Ant as a standalone tool.
Ant reads an XML configuration file and uses this information to carry out whatever commands are inside it. In this case, it uses the Antenna's built-in tasks, such as compile, pre-verify and package. Commands can be set to true, or false when they are not required. This gives the developer the option of adding in an obfuscation step between compiling and pre-verification. An extra target could be inserted as well, to deal with packages from third-party developers. Ant really is flexible, and this is one of the reasons why it has been embraced by a growing number of Java developers. It facilitates the handling of builds for different applications or numerous builds for the same application, saving developer time during development as well as smoothing the communication between different members of a development team. Whichever way it is used it provides a defined and reproducible build for a MIDlet (with the use of Antenna) or for any other Java application for that matter.
Before we look at installation and execution let's have a look at an example build.xml file. We have built one for use with the Demo Racer application discussed in Chapter 5. Configuration of Ant and Antenna for MIDP 2.0 using the Wireless Toolkit version 2.1 is a little more difficult than for previous editions. Version 2.1 splits the CLDC and MIDP packages into JARfiles for each version. Therefore the <wtk home>/lib directory contains cldcapilO.jar, cldcapill.jar, midpapilO.jar and midpapi20.jar files. This split has to be reflected in the build.xml file, such as the one below. This build file was taken from the "hello" example included in the Antenna source ZIP file and then adapted for our needs.
<project name="DemoRacer" default="build" basedir="."> <!-- Define the WTK home directory, needed by the tasks. --> <property name="wtk.home" value="D:/WTK21"/>
<!-- Define the MIDP API: either 1.0 or 2.0 can be used. --> <property name="wtk.midpapi" value="${wtk.home}/lib/midpapi2 0.jar"/> <!-- Define optional properties for this project. --> <property name="midlet.name" value="DemoRacer"/> <property name="midlet.home"
value="${wtk.home}/apps/${midlet.name}"/>
<taskdef resource="antenna.properties"/>
<target name="clean">
<delete failonerror="false" dir="classes"/> <delete failonerror="false"> <fileset dir=".">
<exclude name="build.xml"/> </fileset> </delete> </target>
<target name="build">
<!-- Copy a JAD file from the WTK demo applications.
Caution: Ant only copies this the first time. Also make a directory to compile into. -- >
<copy file="${midlet.home}/bin/${midlet.name}.jad" todir="."/> <mkdir dir="classes"/>
<!-- Compile everything, but don't preverify (yet). --> <wtkbuild srcdir="${midlet.home}/src" destdir="classes" preverify="false"/>
<!-- Package everything. Most of the necessary information is contained in the JAD file. Also preverify the result this time. To obfuscate everything, set the corresponding parameter to "true" (requires RetroGuard or ProGuard). The version parameter increments the MIDlet-Version by one. -- >
<wtkpackage jarfile="${midlet.name}.jar" jadfile="${midlet.name}.jad" classpath="${wtk.home}/lib/cldcapi10.jar" obfuscate="false" preverify="true" autoversion="true"> <!-- Package our newly compiled classes and the resources from the WTK demo application. -- > <fileset dir="classes"/> <fileset dir="${midlet.home}/res"/> </wtkpackage>
<!-- Start the MIDlet suite -- > <wtkrun jadfile="${midlet.name}.jad" device="DefaultColorPhone" trace="class,gc" wait="true"/>
There are seven areas of interest in this build.xml file:
• Wireless Toolkit location - in the property wtk.home; Antenna relies upon functionality provided by the WTK, so this property is essential
• MIDP API location - the WTK 2.1 defines two sets of API, to allow for backwards compatibility when building MIDlets; we have chosen the midpapi2 0.jar file
• the Antenna properties file - defined in a task definition as a resource and set to antenna.properties, this file specifies the classpath of the antenna classes within the antenna-bin-0.9.11.jar file
• the build target-as the default build (we can define more than one within the same configuration file), this defines what the build will actually include
In this case, we copy the existingJAD file to a new location, although we could use this build.xml file to create a new one. The MIDlet source is defined along with the destination for the compiled classes. The emulator execution and packaging are wrapped in this build.
• the wtkpackage command - this creates the JAR and if the JAD file is present, it tries to update the MIDlet-Jar-Size and MIDlet-Jar-URL attributes; it performs obfuscation and pre-verification (if those attributes are set to true) and increments the version number of the MIDlet
• the build classpath - the WTK 2.1 splits the CLDC classes into CLDC 1.0 and CLDC 1.1, so we need to specify the classes against which the pre-verifier should verify; we have chosen CLDC 1.0; the pre-verifier won't execute successfully if this property is not set correctly
• running in an emulator - once all this has been completed successfully the specified emulator will be run according to the device set in the device property.
Installation
Builds are available from the Ant website for both Windows and Linux/Unix developers, though we are only concerned with Windows installation. Developers can choose either a binary (http://ant.apache.org/index. html) or source (http://ant.apache.org/srcdownload.cgi) download. For simplicity we shall examine the binary download. Once the Ant ZIP or TAR file has been downloaded (http://antenna.sourceforge.net), its contents should be extracted to a suitable location. Once this has been done, there are a number of environment variables that need to be set, before Ant can be used.
You will also need to download the antenna-bin-0.9.11.jar and antenna-src-0-9.11.zip files. Place the JAR file in Ant's lib directory. Extract the source files to a location under the existing Ant installation, for example <ant installation>\antenna\ and then place the Antenna JAR file in Ant's lib directory. This will ensure that the Antenna package is in the classpath.
Assume, for this example, that Ant is installed in c:\ant\. The following sets up the environment:
set PATH=%PATH%;%ANT_HOME%\bin
Alternatively these can be set permanently via the System command within the Control Panel on the PC.
Using Ant
Once these environment variables have been set up, Ant is ready to go. To run with the default arguments, simply navigate to the directory containing the build.xml file and type ant at the command prompt. As each target is met, its name will be echoed to the screen, so progress can be monitored. Any errors will also be written to the screen. While build.xml is the default build file, different configurations may have been created for each project. To specify which build file to use, set the -buildfile argument to identify an alternative file:
ant -buildfile <path to build file>
Alternatively the developer may only want to run up to a certain target or perhaps they have a build file containing many targets. This can be specified by adding the target name as an option. If a particular target has a dependency (our example hasn't, but they can be added), then it will run those first, before running itself. Executing the emulator may be taken out of the build target in our example, put into a separate target and executed on its own.
ant -buildfile <path to build file> <target name>
These are just two useful options. Ant help provides a list of the other options available and it can be called by typing:
ant -help
2.3.1.3 Nokia Developer's Suite 2.0 for J2ME Overview
The Nokia Developer's Suite 2.0 for J2ME (NDS) has been created by Nokia and is available from the Forum Nokia website (download from the Tools & SDKs section at www.forum.nokia.com). It is a tool designed primarily to enhance existing development tools, although it can run as a standalone tool. Incidentally, there are versions available for both Windows and Linux platforms.
The suite provides developers with class libraries, APIs and Nokia device emulators used to create both MIDP 1.0 and MIDP 2.0 Java applications. Once it is integrated with an IDE, such as Borland's JBuilder or Sun's Studio ONE, it becomes a very useful tool in the development of mobile applications.
The NDS offers many features to the developer:
• support for Series 60 MIDP Concept SDK Beta 0.3 Nokia Edition Series 60 is a major Symbian OS platform, which has been developed by Nokia and licensed to manufacturers such as Sendo, Siemens, Samsung and Panasonic. This SDK provides a Nokia device reference implementation of that platform
• deployment on devices using infrared, USB and RS-232 (available on Windows platforms only)
The suite provides a convenient interface with which to deploy JAR files to the device during development. During testing it is wise to make intermittent checks on the quality of the application code on the target device. This will greatly reduce the frustration and time spent.
• FTP uploading capability with WML deck creation
• application signing with a public/private key
• an integrated audio converter for MIDI and ringtone XML files.
For developers new to the Java environment, Figure 2.11 shows how the NDS can be used to speed up the creation of new classes. Imported packages and interface references can be set up using a dialog box. This also gives the developer the ability to browse the MIDP packages to find various APIs.
- Figure 2.11 Create Class dialog.
Installation
Although the NDS can be installed in standalone mode, it is probably best used when integrated with an IDE. We shall, therefore, walkthrough the necessary steps required to integrate the product with Borland's JBuilder 9 Personal Edition. (Note that the NDS can also be integrated with Sun ONE Studio 4, Mobile Edition.)
The Nokia Developer's Suite requires JBuilder 9 and the Mobile Set 3.01 to be installed first. We will outline the installation of them in Section 2.3.2.1.
The steps to install the NDS on Windows are as follows:
1. Download the ZIP file from the Forum Nokia website and extract it to a suitable location.
2. To register the software and obtain a serial number for installation, you must have a valid registration with Forum Nokia. The serial number will be sent to the registered email address. Request the registration key and click either ''sent'' or ''already supplied'' on the dialog box.
3. Execute the file setup.exe in the extraction directory. After the splash screen, the terms and conditions of use have to be agreed to. A prompt then appears requesting the entry of the serial number for the software (Figure 2.12).
Jnjxj
. NOKIA
Welcome
. NOKIA
You have; selected a Nokia developer product to tie Installed. You have the following installation options:
InstallAnywhere by Zero G
You have; selected a Nokia developer product to tie Installed. You have the following installation options:
- Ifvou are alreadv a member of Forum Nokia and you have a serial number for this product, please fill in the text fields below and then press the "Nerf1 button
- Ifvou are not a member of Forum Nokia or do not have a serial number for tills product, please leave the text fields below empty and then press the "Next1 button
Forum Nokia Username:
Product Serial Number:
InstallAnywhere by Zero G
Canee
Previous
Next
Figure 2.12 NDS installation.
- Figure 2.13 Choosing configuration type.
4. Once the serial number has been entered, the next decision to be made is how you will actually install the suite, integrated either with JBuilder or Sun ONE Studio, or as a Standalone tool (Figure 2.13).
5. The locations of the JBuilder IDE need to be confirmed along with the destination of the NDS, in successive dialog boxes.
6. The installation is now ready to begin. Press "Install" to install the software. Once the installation has completed, the PC will require restarting.
The NDS has now been fully integrated with the JBuilder IDE. Go to the Tools menu within the Borland IDE and see that "Nokia Developers Suite for J2ME" has appeared near the bottom.
Post a comment