Hi,
I'm a newbie with ANT. I have a ANT build.xml file in which I'm attempting to separate certain packages from different requirements of the built.

As an example, if I have a software which consists of packages A,B,C,D and E. I have customer whom are purchasing the software, but are not interested in the incorporating packages D and E. The customer is only interested in using packages A,B and C. At the same time, I have another customer who is interested in using the entire package of the software i.e. A ...E.

How do I implement flags in ANT to ensure that certain components are not accessible by the customers if they are not being purchased?

From the attached is my build.xml, I'm attempting to exclude the following targets(listed below) so that users could not access them if they have not purchased the software with these features:
<target name = “activeCollector>
<target name = “activeGUI>
<target name = “saagui>

From the build.xml, the final built would produce 2 *.jar files i.e.
Poller_Admin_Installation_V2.0.jar
Poller_Client_Installation_V2.0.jar

Could anyone show me an example how I could implement flags in ANT prevent users from accessing certain packages within a software?

Thanks
Danny

Attachments
<project name="SNMP Gateway 2.0" default="test_dist" basedir=".">

<!-- ant build file for the SNMPGateway. See the build instruction document for
    more information if you're unsure how to use it -->

	<description>ant build for Poller</description>
        <property name="JAVA_INSTALL" location="c:\java\1.3"/>
        <property name="BASE_DIR" value="c:\snmpgw\tcrep\a2_0_0"/>
        <property name="ZKM_JAR"  value="c:\tools\zkm\ZKM.jar"/>
		<property name="CLASSDIR" location="classes"/>
        <property name="FLOW_CLASSDIR" location="flow_classes"/>
		<property name="ROOT_SRCDIR" location=""/>
        <property name="OBFUSCATE_DIR" value="${BASE_DIR}/obfuscated"/>
		<property name="CLASSPATH" value=".;classes;${JAVA_INSTALL};lang;jar\AdventNetSnmp.jar;jar\jaxp-api.jar;jar\dom.jar;jar\sax.jar;jar\xalan.jar;jar\xercesImpl.jar;jar\xsltc.jar;jar\JimiProClasses.zip;jar\MibBrowser.jar"/>


	<!-- set global debug properties -->
	<property name="debug" value="on"/>
	<property name="debuglevel" value="source,lines"/>
	<property name="optimize" value="true"/>

	<path id="project.class.path">
		<pathelement path="${CLASSPATH}"/>
	</path>

	<target name="clean" description="clean created files">
		<delete dir="${CLASSDIR}"/>
                <delete dir="${FLOW_CLASSDIR}"/>
                <delete dir="${OBFUSCATE_DIR}"/>
		<delete file="UnJar.class"/>
                <delete file="jar/poller.jar"/>
	</target>

	<target name="superclean" depends="clean">
		<delete dir="log"/>
		<delete dir="backups"/>
		<delete dir="data"/>
		<delete dir="tmp"/>
		<delete dir="profiles\/populateProfiles"/>
		<delete dir="profiles\/agentDiscoveryProfiles"/>
		<delete file="Poller_Admin_Installation_V2.0.jar"/>
		<delete file="Poller_Client_Installation_V2.0.jar"/>
	</target>

	<target name="init">
		<tstamp/>
		<mkdir dir="${CLASSDIR}"/>
	</target>


	<target name="utils" depends="init">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/utils/*.java"
			excludes="**/utils/*Skel.java, **/utils/*Stub.java, **/troy/utils/*.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/poller/utils/RemoteComponent.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>


	<target name="profiles" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/profiles/*.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
	</target>

	<target name="interfaces" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
		includes="**/componentregistry/*Interface.java,**/agentdiscovery/*Interface.java,
			**/collector/*Interface.java,**/persister/*Interface.java,
			**/administration/*Interface.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
	</target>

	<target name="daemon" depends="init,utils,profiles">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/startupdaemon/*.java"
			excludes="**/startupdaemon/*Skel.java,**/startupdaemon/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/startupdaemon/Daemon.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="registry" depends="init,utils,profiles">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/componentregistry/*.java"
			excludes="**/componentregistry/*Skel.java,**/componentregistry/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/componentregistry/ComponentRegistry.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="collector" depends="init,utils,profiles">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/collector/*.java"
			excludes="**/collector/*Skel.java,**/collector/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/collector/Collector.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="activecollector" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/activecollector/*.java, **/activecollector/ciscoping/*.java,
				**/activecollector/ciscosaa/*.java, **/activecollector/definitions/*.java,
				**/activecollector/standardping/*.java"
			excludes="**/activecollector/*Skel.java,**/activecollector/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/activecollector/ActiveCollector.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

        <target name="eventcollector" depends="init,utils">
                <javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
                  includes="**/eventcollector/**"
			excludes="**/eventcollector/*Skel.java,**/eventcollector/*Stub.java,
                                  **/eventcollector/export/*.java,**/eventcollector/syslog/*.java,
                                  **/troy"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/eventcollector/EventCollector.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="persister" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/persister/*.java"
			excludes="**/persister/*Skel.java,**/persister/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/persister/Persister.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="admin" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/administration/*.java"
			excludes="**/administration/*Skel.java,**/administration/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}"
			includes="**/administration/*Manager.class,**/administration/Administrator.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="adminstub" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/adminstub/*.java"
			excludes="**/adminstub/*_Skel.java,**/adminstub/*_Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/adminstub/AdminStub.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="agentdiscovery" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/agentdiscovery/*.java"
			excludes="**/agentdiscovery/*Skel.java,**/agentdiscovery/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/agentdiscovery/DiscoveryManager.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>


	<target name="trace" depends="init" description="build trace component">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/trace/*java,**/trace/gui/*java"
			excludes="**/trace/*Skel.java,**/trace/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/Trace.class" sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="cmd" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/cmdline/*.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
	</target>

	<target name="deploy" depends="init" description="deploy manager">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/deploymanager/*java"
			excludes="**/deploymanager/*Skel.java,**/deploymanager/*Stub.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
		<rmic base="${CLASSDIR}" includes="**/deploymanager/DeployManager.class"
			sourcebase="${CLASSDIR}">
			<classpath refid="project.class.path"/>
		</rmic>
	</target>

	<target name="gui" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/ui/*.java,**/plaf/*.java,**/thirdparty/*.java,
				**/thirdparty/trove/*.java"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid="project.class.path"/>
		</javac>
	</target>


	<target name="activegui" depends="init,utils">
		<javac srcdir="${ROOT_SRCDIR}" destdir="${CLASSDIR}"
			includes="**/troy/active/*.java, **/troy/active/**"
			optimize="${optimize}"
			debug="${debug}"
			debuglevel="${debuglevel}">
			<classpath refid=

Create supertargets building only those parts of the application you want to include.
So for example (from one of my buildfiles):

<target depends="cleanup" name="clean"/>
  <target name="precompile"/>
  <target depends="javacompile" name="compile"/>
  <target name="postcompile"/>
  <target depends="archive,javadoc,resource" name="package"/>
  <target name="deploy"/>
  <target depends="precompile,compile,test,postcompile,package,deploy" name="make"/>
  <target depends="clean,make" name="rebuild"/

make sure every single supertarget does a clean build to make sure nothing is included that wasn't ordered.

Hi jwenting,

From the example you had provided(see below), you seemed to have basically included the dependencies of the targets of interest - but how did you conditionally exclude the other target types/rules that are currently in the ANT build file without having conditions in them? Could you please help explain?

<target depends="cleanup" name="clean"/>
<target name="precompile"/>
<target depends="javacompile" name="compile"/>
<target name="postcompile"/>
<target depends="archive,javadoc,resource" name="package"/>
<target name="deploy"/>
<target depends="precompile,compile,test,postcompile,package,deploy" name="make"/>
<target depends="clean,make" name="rebuild"/>

Thanks
Danny

You'll need to structure your build (and code) in such a way that your dependencies are minimised or (if possible) eliminated.

So you get a target compileABC depending on compileA, compileB, and compileC where neither depends on any of the others.
Another target compileCDE would depend on compileC, compileD, and compileE.

You will then structure your source directories so that parts A-E don't overlap (in this example C is likely some common package shared by the others so you would have your IDE set up to link to it in the other projects).

This article has been dead for over six months. Start a new discussion instead.