There has been a lot of buzz around Antenna, an Ant add-on for J2ME applications. Why! Can’t I use Ant for this? You very well can, but Antenna elevates many Ant tasks that are peculiar to J2ME, for instance: updating the JAD for the correct JAR size, a task that doesn’t matter as long as you are running your Midlets on the Wireless Toolkit (WTK) but is an absolute must for the Application Manager to be able to load your application on a real device.

This post doesn’t talk about why J2ME developers should go for Antenna (see links at the end for pointers on that) but on how to use Antenna with Netbeans, an IDE for Java. Suffice to mention here that Antenna has brought in many Ant tasks that perform the key functions of the WTK including compilation, preverification, class file obfuscation, updating MIDlet-Jar-Size attribute in JAD and automatic generation of Manifest file. It goes without saying that since Antenna depends on the WTK you require the latter installed on your machine.

While Eclipse supports Antenna, as of now, Netbeans does not provide Antenna module, though it has built-in support for running Ant tasks. Infact using this support we can use Antenna with the IDE very easily. The solution has been tried on Netbeans 3.5/3.6. Here are the steps involved:

Step-1: The first step obviously would be to download Antenna JAR file. Without the worry of using Antenna with Netbeans you may have dropped it in your Ant classpath (for eg: <ant installation path>\lib),you may keep it anywhere because we will have to specify the path Netbeans anyhow.

Step-2: Start Netbeans. Go to Tools > Options > Building > Ant Settings > Properties. Add the following custom property (property value will vary according to the actual Antenna JAR path on your machine). Note the special way of specifying the file path on Windows.

antenna.home=E\:\\antenna-bin-0.9.12.jar

Step-3: Add the following to your build file:

<taskdef classpath"${antenna.home}" resource="antenna.properties"/>

The antenna.properties file has been included in the Antenna jar and evades the worry of manually adding all the WTK tasks to your build file, such as:

<taskdef name="wtkjad" classname="de.pleumann.antenna.WtkJad"/>
<taskdef name="wtkbuild" classname="de.pleumann.antenna.WtkBuild"/>
...

More details can be found at the Antenna homepage.

Step-4: That’s all. Now you may execute the build file.

You may find a sample Antenna build file here that I made to play with the application mentioned here. This assumes that you already have Proguard obfuscator downloaded and copied to bin folder of your WTK installation folder. Do note that for the wtkpackage task you should also Preverify (i.e. add attribute preverify=true) when your are Obfuscating (i.e. when obfuscate=true), this is needed because obfuscation destroys the extra information added by the preverifier. If you do not preverify you may get error similar to following when launching the application.

Running C:\J2mewtk\apps\AntDemo\final\Animation.jad in DefaultColorPhone
Error verifying method corej2me/a paint(Ljavax/microedition/lcdui/Graphics;)V
Approximate bytecode offset 6: Inconsistent or missing stackmap at target
ALERT: Error verifying class corej2me/a

Related links:

Many thanks to J Pleumann, the creator of Antenna, for answering to my many queries and for the excellent free add-on. Disclaimer: The information provided on this page comes without any warranty whatsoever. Use it at your own risk.