Download presentation
Presentation is loading. Please wait.
Published byRandolf Stafford Modified over 9 years ago
1
What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems
2
Tim Dawson, Some Rights Reserved Sources of Information My own experiences updating the build system for a 9000-file J2EE project. Ant 1.6 online docs Erik Hatcher’s TCSS presentation
3
Tim Dawson, Some Rights Reserved Overview “Finally, a real build tool.” – posting at TSS Huh? People have been using Ant for years. Make, without make’s wrinkles (but with some new ones!) Before 1.6, Ant could be very painful for large projects (consisting of lots of subprojects).
4
Tim Dawson, Some Rights Reserved Common Complaints Lack of support for build-file standardization (Maven, anyone?) Difficult to package custom tasks/types (e.g. WebLogic’s inclusion of Ant) No modularization (build file reuse) Tight-coupling between parent/child projects requires extra maintenance. Ant 1.6 fixes all this
5
Tim Dawson, Some Rights Reserved How? Ability to import other build files and reuse targets and tasks (import) Ability to create tasks in Ant (macrodef) Better packaging for libraries of tasks, types in Java (antlib) Ability to easily build multiple subprojects (subant)
6
Tim Dawson, Some Rights Reserved Build File Reuse <import file=“common.xml”/> foo bar common.xmlbuild.xml
7
Tim Dawson, Some Rights Reserved Build File Reuse > ant foo Buildfile: build.xml bar: [echo] bar foo: [echo] foo BUILD SUCCESSFUL Total time: 0 seconds > ant bar Buildfile: build.xml bar: [echo] bar BUILD SUCCESSFUL Total time: 0 seconds build.xmlcommon.xml
8
Tim Dawson, Some Rights Reserved Build File Reuse Usages Include Standard targets: clean, compile, build, install Highlighting differences (e.g. this subproject creates a lucene index of all html pages) Limitations: Can only “call super” with depends or (ugh) antcall. (but there is a workaround)
9
Tim Dawson, Some Rights Reserved Build File Reuse myProject/lines common/build.xml 244 ejbsub1/build.xml 372 ejbsub2/build.xml 350 ejb-utils/build.xml 208 utils/build.xml 249 webapp1/build.xml 245 webapp2/build.xml 260 web-utils/build.xml 203 build.xml 341 myProject/lines ant/build-java.xml 293 ant/build-ejb.xml 323 ant/build-web.xml 63 common/build.xml 15 ejbsub1/build.xml 12 ejbsub2/build.xml 12 ejb-utils/build.xml 7 utils/build.xml 5 webapp1/build.xml 12 webapp2/build.xml 12 web-utils/build.xml 7 build.xml 130 beforeafter
10
Tim Dawson, Some Rights Reserved Defining Tasks in Ant: macrodef No more ! Defines a new task using a nested task as a template Nested elements and specify attributes and elements of the new task Attributes/elements substituted into the task at runtime
11
Tim Dawson, Some Rights Reserved Defining Tasks in Ant: macrodef bar: @{msg} > ant Buildfile: build.xml foo: [echo] bar:sent from foo BUILD SUCCESSFUL Total time: 0 seconds build.xmloutput
12
Tim Dawson, Some Rights Reserved Defining Tasks in Ant: macrodef Usages include: Executing tasks when you don’t want to take the time to write a task in Java e.g. calling a vendor’s jspc class Specifying post-dependencies for overrides e.g. define task “compile” and target “compile”
13
Tim Dawson, Some Rights Reserved Defining Tasks in Ant: presetdef Defines a new task using any other task as a template Arguments provided to the template task are simply used as defaults Property resolution takes place when the preset definition is used, not when it’s defined.
14
Tim Dawson, Some Rights Reserved Defining Tasks in Ant: presetdef > ant Buildfile: build.xml foo: [my.echo] default message [my.echo] override BUILD SUCCESSFUL Total time: 0 seconds build.xmloutput
15
Tim Dawson, Some Rights Reserved Defining Tasks in Ant: presetdef Usages Include: ??? (I’m open to suggestions) With build-file inclusion, this doesn’t seem that useful. Rather than “my.javac”, just define and use properties to define src and output dirs.
16
Tim Dawson, Some Rights Reserved Task/Type Libraries: old way Didn’t support XML namespaces Usage was somewhat difficult Lots of or calls - or - Modify default.properties in org.apache.tools.ant.taskdefs <taskdef resource="checkstyletask.properties" classpath="extensions/checkstyle/checkstyle-all-3.3.jar"/> <taskdef name="queryConstantGen" classname="com.thoughtworks.tools.sqlgen.QueryXMLConstantGen" classpath="${twtasks}; ${jdbc};${jdom}"/> <taskdef name="proxygen" classname="com.thoughtworks.tools.proxygen.ProxyGenTask" classpath="${twtasks}"/> <taskdef name="schemac" classname="com.thoughtworks.util.schemac.SchemacTask" classpath="${twtasks};${schemac}"/> <taskdef name="sqlgen" classname="com.thoughtworks.tools.sqlgen.SQLGen" classpath="${twtasks}"/> <taskdef name="sqlcheck" classname="com.thoughtworks.tools.sqlgen.SQLChecker" classpath="${twtasks}; ${jdbc}"/> <taskdef name="queryXMLcheck" classname="com.thoughtworks.tools.sqlgen.QueryXMLChecker" c classpath="${twtasks}; ${jdbc};${jdom}"/> <taskdef name="getDBConstraints" classname="com.thoughtworks.tools.sqlgen.FieldLengthReader" classpath="${twtasks}; ${jdbc}"/> <taskdef name="javancss" classname="com.thoughtworks.tools.javancss.JavaNcss" classpath="${twtasks}"/>
17
Tim Dawson, Some Rights Reserved Task/Type Libraries: antlib Now, simply include a deployment descriptor in your jar file with your custom tasks/types Reference the package with an xml namespace (e.g. xmlns:ids="antlib:com.idsgrp.ant“) Put the jar file in your classpath (more on this later)
18
Tim Dawson, Some Rights Reserved Task/Type Libraries: antlib (located in the example package) <project name="antlib" default="build" xmlns:example= "antlib:example"> Definition - antlib.xmlUsage - build.xml
19
Tim Dawson, Some Rights Reserved Managing Subprojects: subant Remember how Make used to traverse subdirectories looking for a build files to execute? Previously, you had to use for each and every subproject. Now, will automatically do that work for you.
20
Tim Dawson, Some Rights Reserved Managing Subprojects: subant <filelist dir="." files="import/build.xml macrodef/build.xml presetdef/build.xml antlib/build.xml"/> New wayOld way How is this better?
21
Tim Dawson, Some Rights Reserved Managing Subprojects: subant <filelist id=“subs” dir="." files="import/build.xml macrodef/build.xml presetdef/build.xml antlib/build.xml"/> … Multiple Targets
22
Tim Dawson, Some Rights Reserved To Recap… Ability to import other build files and reuse targets and tasks (import) Ability to create tasks in Ant (macrodef) Better packaging for libraries of tasks, types in Java (antlib) Ability to easily build multiple subprojects (subant)
23
Tim Dawson, Some Rights Reserved But Wait, There’s More New Command-line Options Java 1.2 required New Classloader XML Namespaces All tasks can now live outside targets New Tasks
24
Tim Dawson, Some Rights Reserved New Command Line Options Aliases -h = -help -p = -projecthelp -d = -debug -s = -find New -lib -k / -keep-going -noinput
25
Tim Dawson, Some Rights Reserved New Classloader Search Order Directories/jars specified on command line with “-lib” argument $CLASSPATH (actually added to –lib by wrapper script) .jar files from ${user.home}/.ant/lib $ANT_HOME/lib
26
Tim Dawson, Some Rights Reserved Tasks Outside Targets Previously, only some tasks could live outside targets. In particular, property, typedef, and taskdef Required “init” targets with dependencies everywhere Now, any task can live outside a target Executed at parse time Eliminates unnecessary “init” targets
27
Tim Dawson, Some Rights Reserved Other New Tasks DefaultExcludes can now modify default excludes Sync adds/removes files from destination to match source Scriptdef similar to taskdef & macrodef, but with scripts
28
Tim Dawson, Some Rights Reserved Creative Commons In case you noticed the “cc” at the bottom instead of the usual copyright… here’s a brief overview of what that’s all about: Creative Commons was started by Lawrence Lessig after the Supreme Court rejected his request to declare the Sonny Bono Copyright Extension Act unconstitutional. His latest book (available in print and free download) highlights the dangers of our oppressive legal landscape surrounding copyrights. All content is copyrighted automatically and requires lawyers to navigate the fair-use landscape. Even if you think you’re ok, anyone can sue you and the risks of huge fines and certainty of nonrecoverable legal fees stifles a lot of creative freedom. The goal of Creative Commons is to allow content creators who want to share to do so easily/effectively. This presentation is licensed with the creative commons “attribute-sharealike 1.0” license available at http://creativecommons.org/licenses/by-sa/1.0/
29
Tim Dawson, Some Rights Reserved
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.