Sun Java Solaris Communities My SDN Account Join SDN
 
FAQ

How do I migrate automated builds to the J2ME Wireless Toolkit 2.1 environment?

 
 
Automated Builds Using J2ME Wireless Toolkit 2.1

Researched by Richard Marejka
September 2004


Question

How do I migrate automated builds to the J2ME Wireless Toolkit 2.1 environment?


Answer

The article "Managing Wireless Builds with Ant" describes how to use Apache Ant to build a MIDlet suite using the command-line tools provided with version 2.0 of the toolkit. In one example, an Ant build file looks like this:

    <?xml version="1.0"?>
    <project name="Tileman" default="compile" basedir=".">
        <property name="WTK.dir"  value="/home/richard/lib/sparc/WTK2.0"/>
        <property name="MIDP.lib" value="${WTK.dir}/lib/midpapi.zip"  />

        <path id="bootclasspath">
            <pathelement path="${MIDP.lib}"/>
        </path>

        <path id="classpath">
        </path>

        <!-- INIT - execute any tasks required for the build      -->

        <target name="init">
            <tstamp/>
        </target>

        <!-- COMPILE - convert the source into class files        -->

        <target name="compile" depends="init">
            <mkdir dir="tmpclasses" />
            <javac destdir="tmpclasses" srcdir="src" target="1.1">
                <bootclasspath refid="bootclasspath"/>
                <classpath refid="classpath"/>
            </javac>
        </target>

        <!-- Note - other build targets have been omitted        -->
    </project>


To make this build work in version 2.0 of the toolkit you need only change the value of the WTK.dir property to your own installation directory. If, however, you upgrade the build environment to version 2.1 and change the value of WTK.dir accordingly, the build will fail. When you execute the ant command, you'll see:

    Buildfile: build.xml

    init:

    compile:
    [javac] Compiling 4 source files to /home/richard/wip/wtkapps/Tileman/tmpclasses
    [javac] Fatal Error: Unable to locate package java.lang in classpath or bootclasspath

    BUILD FAILED
    /home/richard/wip/wtkapps/Tileman/build.xml:33: Compile failed;\
        see the compiler error output for details.

    Total time: 5 seconds

At first, the error is disconcerting: Unable to locate package java.lang? What happened?

If the only change was the specification of the toolkit product directory then the failure must be a result of that change. It turns out that the problem lies in the two versions' lib directories. A command to compare them produces, in part:

    WTK2.0/lib only and WTK2.1/lib only

    ./api.properties            ./cldcapi10.jar
    ./midpapi.zip               ./cldcapi11.jar
    ./mmapi.zip                 ./crlf_bw.png
    ./wma.zip                   ./j2me-ws.jar
                                ./midpapi10.jar
                                ./midpapi20.jar
                                ./mmapi.jar
                                ./security_query.png
                                ./wma.jar

The build failed because the property MIDP.lib, which expands to /home/richard/lib/sparc/WTK2.1/lib/midpapi.zip, refers to a file that exists in version 2.0 of the product but not in version 2.1.

If you look closer, you'll see that version 2.0 includes ZIP versions of WMA (JSR 120), MMAPI (JSR 135), and a combination of CLDC 1.0 (JSR 30), MIDP 1.0 (JSR 37), and MIDP 2.0 (JSR 118) in the midpapi.zip file. By contrast, WTK 2.1 uses JAR files rather than ZIPs, and follows a policy of one JSR per JAR. This new scheme is more flexible, allowing the developer to mix and match configurations, profiles, and optional packages to create an environment that closely models the target environment.

To migrate the Ant build file to the J2ME Wireless Toolkit 2.1 environment isn't complicated:

  1. Update the WTK.dir property to reflect the new installation directory.
  2. Change the value of the MIDP.lib property from midpapi.zip to midpapi10.jar.
  3. Define a new CLDC.lib property, whose value is the pathname of cldcapi10.jar.
  4. Add the CLDC.lib property to bootclasspath.

The relevant part of build.xml now looks like this:

    ...
    <property name="WTK.dir"  value="/home/richard/lib/sparc/WTK2.1"/>
    <property name="MIDP.lib" value="${WTK.dir}/lib/midpapi10.jar"  />
    <property name="CLDC.lib" value="${WTK.dir}/lib/cldcapi10.jar" />

    <path id="bootclasspath">
        <pathelement path="${MIDP.lib}"/>
        <pathelement path="${CLDC.lib}"/>
    </path>
    ...

This straightforward fix results in an Ant build file that is easy to adapt to other MIDlet suites with different JSR requirements. Using KToolbar hides all of these implementation details; its Settings window includes an API Selection tab to specify a configuration, a profile, and optional APIs.