Java Reference
In-Depth Information
Except for the last point, obfuscators can significantly reduce the size of compiled classes
in a MIDlet suite JAR.
There's a wide spectrum of obfuscators, with a variety of licenses, costs, and features. For
a comprehensive list, see http://proguard.sourceforge.net/alternatives.html .
Using an obfuscator requires some finesse. The trick is to obfuscate the classes before they
are preverified. The J2ME Wireless Toolkit includes support for inserting an obfuscator into the
build cycle. Support for ProGuard is built in with version 2.2, and you can write adapter code to
use other obfuscators. If you're using the 2.2 version of the toolkit, you just need to download
ProGuard and copy the proguard.jar file into the toolkit's bin directory. Then choose Project
Package
Create Obfuscated Package and the toolkit handles all the details.
There is an article that describes how to use the ProGuard obfuscator with the J2ME Wireless
Toolkit at http://developers.sun.com/techtopics/mobility/midp/ttips/proguard/ .
The documentation that comes with the J2ME Wireless Toolkit includes a document
called “J2ME Wireless Toolkit Basic Customization Guide.” This guide describes how to add
support for any obfuscator to the toolkit.
Obfuscators tend to be a little finicky, but once you get them configured correctly, they can
provide significant size savings.
Tip You should not use the obfuscator during the regular coding/debug cycle, but just before packaging
and deployment. This is because the obfuscator can often make debugging difficult.
Using Ant
Ant is a powerful build tool that is useful for automating MIDlet suite builds. It's similar in concept
to make , but it is cleaner and easier to use. Ant is open source software, part of the Apache
Jakarta project, at http://ant.apache.org/ .
Ant is a tool for serious developers. If you believe you've exhausted the possibilities of the
J2ME Wireless Toolkit, Ant is probably the next tool you should learn. Ant provides considerable
flexibility in structuring your build cycle and lets you easily automate tasks like generating
documentation or packaging source code. For an introduction to Ant and MIDP, see
http://developers.sun.com/techtopics/mobility/midp/articles/ant/ .
The code download for this topic includes an Ant build script. A simplified version of the
build script is shown in Listing 2-2.
Listing 2-2. An Example Ant Build Script
<project name="wj2" default="dist" basedir="..">
<property name="project" value="wj2"/>
<property name="midp" value="/WTK20"/>
<property name="midp_lib" value="${midp}/lib/midpapi.zip"/>
 
Search WWH ::




Custom Search