Using Antenna with Netbeans

Antenna [http://antenna.sourceforge.net]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:

  • 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:
  • Start Netbeans. Go to Tools > Options > Building > Ant Settings > Properties. Add the following custom property (The property value will vary according to the actual Antenna JAR path on your machine):
    antenna.home=E\:\\antenna-bin-0.9.12.jar
    

    Note the special way of specifying the file path on Windows .

  • 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.

  • That’s all. Now you may execute the build file.

Download
Click here to get a sample Antenna 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.

Code Analyzers

During my search for Profilers I stumbled upon some good Java code checkers or Code Analyzers and though most of you may be already aware about them would like to share my thoughts on the same. Please feel free to correct me or add your inputs to this.

Talking of Code Review or Analysis I wonder if somebody would even think about going for the wearisome task of manually locating lapses in use of Proper Syntax, code indentation, unused variables/imports, naming convention and Javadoc comments without using any automated tool to do the task. Apart from the task of deciding about what code optimizations need be done or detecting any logical blunder rest can perhaps be safely left to these tools. Moreover more ambitious programmers can even look for these tools to operate in tight integration with their favorite IDEs. Fortunately my favorite Netbeans has many modules already available of which three are my personal favorites : PMD, Jalopy and Checkstyle, perhaps in that order.

All the three have various plugins available for various IDEs. Jalopy is a code formatter and beautifier and is highly configurable using code snippets though it does not comprehend well line spacing and tabs for files edited by other IDEs say Kawa or Textpad. Checkstyle is more about code formatting and nit-pickingly looks for white spaces, tabs, position of braces and javadocs and configuration is difficult (as far as I know certainly not configurable through Netbeans GUI). Out of these PMD deserves my high regard, here is a synopsis of what it can detect:

  • Unused local variables, parameters and private methods (very useful)
  • Empty catch blocks
  • Empty ‘if’ statements
  • Duplicate import statements
  • Classes which could be Singletons
  • Short/long variable and method names

A lesser known but very powerful code checking tool is FindBugs. Too bad it has no plugin available for Netbeans though. While the conclusions of the tool about unread fields is not very accurate, it detects what many others don’t such as:

  • Null pointer de-reference detector
  • Ignored returns from method
  • Unclosed I/O streams
  • Objecting usage of == or != for String comparison

Here are some other tools:

  • SourceMonitor: Provides size and complexity metrics for your source code.
  • JLint: A Code verifier
  • QStudio also seems pretty good to me. As per their site it is available for download with a year license at no cost.

P.S.: This post finds mention here, here, here and here.

Project Rave

Sue Spielman has some more details on Project Rave. The key phrase here is “simplified development model”,  in accordance with Sun’s aim of  “lowering the barrier and entry point for the corporate developers” and “sucking up the VB corporate/IT programmers into the Java platform”. It’s another thing that, as Sue reported, a 404 error surfaced during Hammerhead’s demo at JavaOne. 

Rave uses NetBeans Platform as its base (though visually it will be different) along with Java Server Faces and JDBC Rowsets standards. And if you didn’t know Sun has no plan to make this project open source.