190 likes | 360 Views
Jakarta Ant. Sean C. Sullivan June 25, 2002 Portland Java Users Group. Jakarta. Tomcat Struts Ant Log4j HttpClient …and many more!. What is Ant?. Ant is an extensible build tool. “In theory, it is kind of like Make, but without Make's wrinkles.”. Projects that use Ant. Tomcat
E N D
Jakarta Ant Sean C. Sullivan June 25, 2002 Portland Java Users Group
Jakarta • Tomcat • Struts • Ant • Log4j • HttpClient • …and many more!
What is Ant? Ant is an extensible build tool. “In theory, it is kind of like Make, but without Make's wrinkles.”
Projects that use Ant • Tomcat • NetBeans • JBoss • JDOM
What Ant Can Do For You • automate your project’s build and deployment tasks • compile Java source code • create JAR’s, ZIP’s, EAR’s, and WAR’s • automate Javadoc generation • run test suites • deploy files to remote systems
Ant terminology • buildfile • project • targets • tasks
Example build file: build.xml <project name="FooEJBProject" default="build" basedir="."> <property name="jboss-rootdir" value="c:/jboss-3.0.0/" /> <property name="j2ee-jarfile" value="${jboss-rootdir}/server/all/lib/jboss-j2ee.jar" /> <property name="fooejb-jarfilename" value="FooEJB.jar" /> <target name="all" depends="init, build, dist"/> <target name="init"> <mkdir dir="${outputdir}" /> </target>
build.xml (continued) <target name="clean"> <delete dir="${outputdir}" /> </target> <target name="dist" depends="init, EJBJarFile"/>
build.xml (continued) <target name="EJBJarFile" depends="init, build"> <ejbjar srcdir="${classesdir}" destdir="${outputdir}" descriptordir="${basedir}" basejarname="${fooejb-jarfilename}" genericjarsuffix="" classpath="${classesdir};${j2ee-jarfile}" > <include name="**/ejb-jar.xml"/> <support dir="${classesdir}"> <include name="*.class" /> </support> </ejbjar> </target>
build.xml (continued) <target name="build" depends="init"> <javac srcdir="${javasrcdir}" deprecation="on" destdir="${classesdir}" includeAntRuntime="no" classpath="${j2ee-jarfile}" debug="on" /> </target> </project>
Common tasks • <property> • <javac> • <jar> • <ejb-jar> • <javadoc> • <junit> • <touch> • <copy> • <delete> • <move> • <fileset> • <cvs> • <exec> • <mail>
Creating your own Ant task public class MyTask extends org.apache.tools.ant.Task { public void execute() { … } public String getFoo() { … } public String setFoo() { … } }
Monitoring a build • create a “build listener” class • implement Ant’s BuildListener interface
Ant related tools… • CruiseControl • Centipede • AntHill • Maven
CruiseControl • a “tool for setting up a continuous build process” • http://cruisecontrol.sourceforge.net/ • a set of tasks to automate the checkout/build/test cycle • a servlet for viewing the status of the current build as well as the results of previous builds
Centipede • project build system • http://www.krysalis.org/centipede/ • Defines format for: • code modules • project status information • project layout • Features: • Java source colorizer • UML doclet
AntHill http:/www.urbancode.com/projects/anthill/default.jsp • ensures a controlled build process • performs a checkout from the source repository of the latest version of a project before every build and tags the repository with a unique build number after every build • automatically updates a project intranet site with artifacts from the latest build
Maven • is a “project management and project comprehension tool” • http://jakarta.apache.org/turbine/maven/ • well-defined Project Object Model • useful when you need to build multiple projects
Summary • Ant is easy to use and powerful • download Ant at http://jakarta.apache.org/ant/