<ANTENNA/>

Antenna

An Ant-to-End Solution For Wireless Java

Version 1.2.1

(c) 2002-2010


Erik Wetterberg
Sourceforge project


News | Overview | Download | Setup | JAD | Build | Package | MakePRC | RAPC
Run | Preverify | Obfuscate | SmartLink | Preprocess | Deploy | Sign | History |

SmartLink

The WtkSmartLink task removes unnecessary classes from a given JAR file. It can be seen as some kind of "smart linker" (hence the name), although what it does bears more resemblance to an optimization that takes place after linking. Anyway, the task removes each class that is not "necessary". A class is considered necessary if it has at least one of the the following properties:
  1. It is one the main MIDlet classes, denoted by a MIDlet-# key in the JAD file.
  2. It is a class to be loaded by name (on a Motorola phone), denoted by an iDEN-Install-Class-# key.
  3. It is explicitly excluded from smartlinking using the <preserve> nested element.
  4. It is needed (imported) by another class that is necessary.
Note that the optimization mechanism is very simple. It only builds a tree of plain class dependencies (more or less equivalent to "import" information). It does not attempt to utilize any kind of data flow analysis on methods to achieve better results. Since I was only looking for a simple (but working) means to get unneeded parts of libraries out of my JAR file, this will probably not change in the near future (unless I find some spare time).

The task provides the following parameters:

Parameter Type Required Purpose
jarfile file yes The name of the JAR file to optimize.
jadfile file yes The name of the JAD file that accompanies the JAR file. If the source JAR file is overwritten (no "tojarfile" being specified), the "MIDlet-Jar-Size" key in the JAD is updated when the task is finished.
tojarfile file no The name of the resulting, optimized JAR file. Defaults to the original JAR file, if not specified.
bootclasspath path no Specifies the basic system classes that are needed by the application. Defaults to the MIDP API contained in ${wtk.home}/lib/midpapi.zip, or ${wtk.midpapi}, if specified.
classpath path no Specifies additional libraries that are needed by the application, but not part of the JAR file (for example libraries that are already available on a certain phone).
classpathref string no A reference to a classpath defined elsewhere.
bootclasspathref string no A reference to a bootclasspath defined elsewhere.
if String no Provides fine-grained control over task execution based on a property definition. The task will only be executed if the given property is defined.
unless String no Provides fine-grained control over task execution based on a property definition. The task will only be executed if the given property is not defined.

Preserve

In addition to the various parameters, the task provides one nested element "preserve" that specifies classes that should be preserved in the JAR file even if the optimizing process detects them to be unnecessary. This is mostly the case for classes that are loaded by name while the application is running.

Parameter Type Required Purpose
class string yes The fully qualified name of a class that needs to be in the JAR file even if the smartlinking task thinks that it doesn't.
if String no Provides fine-grained control over the classes being preserved. The class will only be preserved if the given property is defined.
unless String no Provides fine-grained control over the classes being preserved. The class will only be preserved if the given property is not defined.