Ready! Dave Dribin's 1UP

User's Guide for J2ME Ant Tasks

Introduction

Three tasks have been added to Ant version 1.3 to assist in building J2ME applications. Currently, only the CLDC and K virtual machine are supported, but I would like to expand the scope to include MIDP.

  • <mejavac> - Compiles Java source code targeted for a J2ME device.
  • <preverify> - Preverifies class files.
  • <jartoprc> - Converts a JAR file to a Palm Pilot application.

NOTE: The preverify task launches an executable that is only available for Linux, Win32, and Solaris. I have only tried the Linux version, so please give me some feedback for the Win32 and Solaris versions.


Installation

Download a binary distribution and expand the archive. Add the JAR file in the lib directory to your classpath. Add the following lines to your build.xml file:

<taskdef name="mejavac"
       classname="org.dribin.dave.ant.j2me.taskdefs.MeJavac"/>
<taskdef name="preverify"
       classname="org.dribin.dave.ant.j2me.taskdefs.Preverify"/>
<taskdef name="jartoprc"
       classname="org.dribin.dave.ant.j2me.taskdefs.JarToPrc"/>

Set the j2me.home property to the root of the J2ME CLDC directory. For example, if you unzipped the Sun distribution to /usr/local/, set the property as such:

<property name="j2me.home" value="/usr/local/j2me_cldc" />

Reference

mejavac Task

Compiles Java source files by setting the bootclasspath for the J2ME compiler. This takes all the same attributes as the javac task.

Example:

<mejavac srcdir="${src.java}" destdir="${build.java}">
<classpath refid="lib.path" />
</mejavac>

preverify Task

Runs the preverify tool on a directory of class files and creates s new directory of verified classes. This only runs under Linux, Win32, and Solaris.

Parameters

Attribute Description Required
unverifieddir Directory of unverified class files Yes
verifieddir Directory to place verified class files Yes

Example:

<preverify unverifieddir="${build.java}"
         verifieddir="${build.verified}" />

jartoprc Task

Creates a Palm Pilot application (PRC file) from a JAR of verified classes.

Parameters

Attribute Description Required
jarfile Path of JAR file to convert. Yes
prcfile Path of PRC file to create. Yes
mainclass The main class of the executable. This is the entry point into the application. Yes
networking Set to "true" to indicate that this program uses networking. Default is "false" when omitted. No
verbose Set to "true" to print more information while converting. Default is "false" when omitted. No

Example 1:

<jartoprc jarfile="${dist.jar}" prcfile="${dist.prc}"
        mainclass="org.dribin.dave.kvm.HelloWorld" />

Example 2:

<jartoprc jarfile="${dist.jar}" prcfile="${dist.prc}"
        mainclass="org.dribin.dave.kvm.HelloWorld"
        networking="true" verbose="true" />

Complete Build File

Download a complete build.xml file. A file named build.properties must be included at the project root directory. The following properties must be set:

Property Description
j2me.home Path of J2ME installation directory
project.name Name of the project.
project.version Version of the project.
project.prc.mainclass The main class of the executable.

The JAR and PRC files will be named ${project.name}-${project.version}. Download a sample build.properties file.

These pages are copyright © 2002-2008 by Dave Dribin. If you have any comments or suggestions, please contact me.