Using jarnotator in ant builds
Last Updated on Tuesday, 31 August 2010 20:46 Written by jarnotator Saturday, 14 August 2010 11:17
Using jarnotator in an Ant build
Since jarnotator provides a Ant task it can be used directly from within Apache Ant build scripts. The Ant task provides all the jarnotator options. All in all the Ant task fairly easy to use. Analyzing your classes as part of a build is trivial.
The necessary setup to use the jarnotator task is that of any other external Ant task. The remainder of this page briefly outlines how to get started. For more detailed information please refer to the Apache Ant documentation related to the use of external Ant tasks.
Make jarnotator available to Apache Ant
Ant has its own mechanisms to load Ant tasks. It looks in the following location or uses the following options:
- via command line argument
-lib - adding to
${user.home}/.ant/lib - adding to
${ant.home}/lib
Define the task with your build script
To refer to the jarnotator task within your targets you first need to define the task. The following line does the job:
<taskdef name="jarnotator" classname="be.biggerbytes.jarnotator.run.JarnotatorTask"/>
Next you need to invoke this task into your target. Since Ant does not impose a life cycle like maven does you need to take care of invoking the jarnotator task once the bytecode has been created. In other words after compilation. The jarnotator task can handle classes directories as well as jar files.
Using the jarnotator task
>The jarnotator task has a single mandatory parameter, fileName. The parameter points the task at the classes located in this directory or jar with that name.
The example below also includes all parameters accepted by the jarnotator ant task. The values are the default values and are meant for illustration. One can leave them out.
A nested claspath element can be provided to indicate the location of third party libraries required by the classes being analysed. If those libraries have in turn been processed by jarnotator (or manually annotated with jsr305 annotation) these annotations can be picked up during the analysis.
<property name="myjar" location="target\classes"/>
<property name="lib" location="libdir"/>
<target name="main">
<!--
All values below except fileName and the path correspond
to the default value.
-->
<jarnotator fileName="${myjar}"
annotateInterfaces="true"
annotateAbstractMethods="true"
processOlderJava="false"
verify="true"
showByteCode="false"
keepOriginal="false"
backupFileExtension="orig"
quiet="false"
simpleDebug="true">
<!-- Class path used during analysis of your classes -->
<classpath>
<fileset dir="${lib}" includes="**/*.jar"/>
</classpath>
</jarnotator>
</target>
</project>
Complete example
Below you'll find a complete example of how to process your classes (fictitiously located in target\classes).
<?xml version="1.0"?>
<project name="OwnTaskExample" default="main" basedir=".">
<taskdef name="jarnotator" classname="be.biggerbytes.jarnotator.run.JarnotatorTask"/>
<property name="myjar" location="target\classes"/>
<property name="lib" location="libdir"/>
<target name="main">
<!--
All values below except fileName and the path correspond
to the default value.
-->
<jarnotator fileName="${myjar}"
annotateInterfaces="true"
annotateAbstractMethods="true"
processOlderJava="false"
verify="true"
showByteCode="false"
keepOriginal="false"
backupFileExtension="orig"
quiet="false"
simpleDebug="true">
<!-- Class path used during analysis of your classes -->
<classpath>
<fileset dir="${lib}" includes="**/*.jar"/>
</classpath>
</jarnotator>
</target>
</project>
Feed Display
| Linux Today |
| Linux Today News Service |
![]() |
|















