HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Managing Build Complexity with Apache Ant 1.6"
Vol. 9, Issue 6, p. 22

	



Listing 1: Using antcall

1 <target name="build.general">
2  <echo message="Building target ${build.target}" />
3 </target>
4
5 <target name="build.dev">
6  <antcall target="build.general">
7   <param name="build.target" value="dev" />
8  </antcall>
9 </target>


Listing 2: Using macrodef

1 <macrodef name="mybuild">
2  <attribute name="buildtarget" />
3  <sequential>
4   <echo message="Building target '@{buildtarget}'" />
5  </sequential>
6 </macrodef>
7
8 <target name="build.dev">
9  <mybuild buildTarget="dev" />
10 </target>


Listing 3: Using the element tag

1 <macrodef name="recordTask">
2  <attribute name="level" default="info" />
3  <attribute name="file" />
4  <element name="recordabletask" optional="no" />
5  <sequential>
6   <record name="@{file}" action="start"
   append="yes" loglevel="@{level}" />
7   <recordabletask />
8   <record name="@{file}" action="stop" />
9  </sequential>
10 </macrodef>
11
12 <target name="test">
13  <recordTask file="record.log">
14  <recordabletask>
<echo message="in log" />
</recordabletask>
15  </recordTask>
16 <echo message="out of log" />
17 </target>


Listing 4: A series of SQL statements

1 <sql driver="org.hsqldb.jdbcDriver"
   sql="jdbc:hsqldb:\\ansible" userid="sa" password=""
   src="build/db/createUsers.sql">
2  <classpath>
3   <fileset dir="source/libraries" includes="hsqldb.jar" />
4  </classpath>
5 </sql>
6 <sql driver="org.hsqldb.jdbcDriver"
   sql="jdbc:hsqldb:\\ansible" userid="admin" password="admin"
   src="build/db/dropSa.sql">
7  <classpath>
8   <fileset dir="source/libraries" includes="hsqldb.jar" />
9  </classpath>
10 </sql>
11 <sql driver="org.hsqldb.jdbcDriver"
   sql="jdbc:hsqldb:\\ansible" userid="admin" password="admin"
   src="build/db/createSchema.sql">
12  <classpath>
13   <fileset dir="source/libraries" includes="hsqldb.jar" />
14  </classpath>
15 </sql>


Listing 5: Using presets to reuse SQL calls

1 <presetdef name="runsql">
2  <sql driver="org.hsqldb.jdbcDriver"
    sql="jdbc:hsqldb:\\ansible"
	userid="ansibleAdmin" password="!ansibleAdmin">
3   <classpath>
4    <fileset dir="source/libraries" includes="hsqldb.jar" />
5   </classpath>
6  </sql>
7 </presetdef>
8
9 <runsql userid="sa" password="" src="build/db/createUsers.sql" />
10 <runsql src="build/db/dropSa.sql" />
11 <runsql src="build/db/createSchema.sql" />


Listing 6: Using an import task

1 <project name="Intro-Import-Subclass" default="hello">
2  <import file="build-super.xml" />
3  <target name="hello" depends="SuperClass.hello">
4   <echo message="Powered by Ant 1.6" />
5  </target>
6  <target name="sponsor">
7   <echo message="Brought to you by JDJ." />
8   </target>
9 </project>

 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.