C H A P T E R  5

NetBeanstrademark Software Integration

NetBeanstrademark integrated development environmnet 4.1 creates Ant script for Java technology projects and uses this script to compile, build and run projects. The build.xml file for a NetBeans project is located in the project's root directory. Modify this build.xml file as explained in Chapter 2 to enable usage of the Ant tasks.

Netbeans software recognizes some pre-defined targets in the build.xml file that is generated for the project. Some of these targets exist, such as clean and compile, while XML for others is left empty. One of these targets is -post-compile. You may safely modify this target to incorporate usage of the Ant tasks in your project. An example of a modified build.xml file for a NetBeans project is included here. For information on NetBeans software, go to the NetBeans integrated development environment web site at http://www.netbeans.org.

 


CODE EXAMPLE 5-1 build.xml Modified for a NetBeans Project

<?xml version="1.0" encoding="UTF-8"?>

<!-- You may freely edit this file. See commented blocks below for -->

<!-- some examples of how to customize the build. -->

<!-- (If you delete it and reopen the project it will be recreated.) -->

<project name="JavaPurse" default="default" basedir=".">

<description>Builds, tests, and runs the project JavaPurse.</description>

<import file="nbproject/build-impl.xml"/>

<!--

 

There exist several targets which are by default empty and which can be

used for execution of your tasks. These targets are usually executed

before and after some main targets. They are:

 

-pre-init: called before initialization of project properties

-post-init: called after initialization of project properties

-pre-compile: called before javac compilation

-post-compile: called after javac compilation

-pre-compile-single: called before javac compilation of single file

-post-compile-single: called after javac compilation of single file

-pre-compile-test: called before javac compilation of JUnit tests

-post-compile-test: called after javac compilation of JUnit tests

-pre-compile-test-single: called before javac compilation of single JUnit test

-post-compile-test-single: called after javac compilation of single JUunit test

-pre-jar: called before JAR building

-post-jar: called after JAR building

-post-clean: called after cleaning build products

 

(Targets beginning with '-' are not intended to be called on their own.)

 

Example of inserting an obfuscator after compilation could look like this:

 

<target name="-post-compile">

<obfuscate>

<fileset dir="${build.classes.dir}"/>

</obfuscate>

</target>

 

For list of available properties check the imported

nbproject/build-impl.xml file.

 

 

Another way to customize the build is by overriding existing main targets.

The targets of interest are:

 

-init-macrodef-javac: defines macro for javac compilation

-init-macrodef-junit: defines macro for junit execution

-init-macrodef-debug: defines macro for class debugging

-init-macrodef-java: defines macro for class execution

-do-jar-with-manifest: JAR building (if you are using a manifest)

-do-jar-without-manifest: JAR building (if you are not using a manifest)

run: execution of project

-javadoc-build: Javadoc generation

test-report: JUnit report generation

 

An example of overriding the target for project execution could look like this:

 

<target name="run" depends="JavaPurse-impl.jar">

<exec dir="bin" executable="launcher.exe">

<arg file="${dist.jar}"/>

</exec>

</target>

 

Notice that the overridden target depends on the jar target and not only on

the compile target as the regular run target does. Again, for a list of available

properties which you can use, check the target you are overriding in the

nbproject/build-impl.xml file.

 

-->

<!-- the directory structure under the base directory -->

<property name="sourceroot" value="src" />

<property name="classroot" value="build/classes" />

<property name="exportmap" value="exportmap" />

 

<!-- the directories where the Java Card(TM) export are located -->

<!-- could go into a properties file-->

<property name="jcardkit_home" value="C:\java_card_kit-2_2_2" />

<property name="jcardkit_exports" value="${jcardkit_home}/api_export_files" />

<property name="jcardkit_libs" value="${jcardkit_home}/lib" />

 

<!-- Definitions for tasks for Java Card tools -->

<taskdef name="apdutool"

classname="com.sun.javacard.ant.tasks.APDUToolTask"/>

<taskdef name="capgen"

classname="com.sun.javacard.ant.tasks.CapgenTask" />

<taskdef name="maskgen"

classname="com.sun.javacard.ant.tasks.MaskgenTask" />

<taskdef name="deploycap"

classname="com.sun.javacard.ant.tasks.DeployCapTask" />

<taskdef name="exp2text"

classname="com.sun.javacard.ant.tasks.Exp2TextTask" />

<taskdef name="convert"

classname="com.sun.javacard.ant.tasks.ConverterTask" />

<taskdef name="verifyexport"

classname="com.sun.javacard.ant.tasks.VerifyExpTask" />

<taskdef name="verifycap"

classname="com.sun.javacard.ant.tasks.VerifyCapTask" />

<taskdef name="verifyrevision"

classname="com.sun.javacard.ant.tasks.VerifyRevTask" />

<taskdef name="scriptgen"

classname="com.sun.javacard.ant.tasks.ScriptgenTask" />

<typedef name="appletnameaid"

classname="com.sun.javacard.ant.types.AppletNameAID" />

<typedef name="jcainputfile"

classname="com.sun.javacard.ant.types.JCAInputFile" />

<typedef name="exportfiles"

classname="org.apache.tools.ant.types.FileSet" />

 

<!-- set the export path to the Java Card export files -->

<path id="export" description="set the export file path">

<pathelement path="${jcardkit_exports}" />

<pathelement path="build/classes"/>

</path>

 

<!-- set the classpath at minimum to the Java Card API -->

<!-- but also for all other API needed in the project-->

<path id="classpath" description="Sets the classpath to Java Card API and tools">

<pathelement path="${jcardkit_home}/lib/api.jar"/>

<pathelement path="${jcardkit_home}/lib/converter.jar"/>

<pathelement path="${jcardkit_home}/lib/offcardverifier.jar"/>

<pathelement path="${jcardkit_home}/lib/scriptgen.jar"/>

<pathelement path="${jcardkit_home}/lib/apdutool.jar"/>

<pathelement path="${jcardkit_home}/lib/apduio.jar"/>

<pathelement path="."/>

</path>


<target name="convert_library"

description="Build export file and CAP file for SampleLibrary">

<convert

EXP="true"

CAP="true"

packagename="com.sun.javacard.samples.SampleLibrary"

packageaid="0xA0:0x0:0x0:0x0:0x62:0x3:0x1:0xC:0x4"

majorminorversion="1.0"

classdir="${classroot}"

outputdirectory="${classroot}">

<exportpath refid="export"/>

<classpath refid="classpath"/>

</convert>

</target>

 

<target name="convert_purse" depends="convert_library"

description="Build cap file for the JavaPurse package">

<convert

CAP="true"

packagename="com.sun.javacard.samples.JavaPurse"

packageaid="0xA0:0x0:0x0:0x0:0x62:0x3:0x1:0xC:0x2"

majorminorversion="1.0"

classdir="${classroot}"

outputdirectory="${classroot}">

<AppletNameAID

appletname="com.sun.javacard.samples.JavaPurse.JavaPurse"

aid="0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x2:0x1"/>

<exportpath refid="export"/>

<classpath refid="classpath"/>

</convert>

</target>


<target name="-post-compile" depends="convert_purse">

</target>

</project>