Presentation is loading. Please wait.

Presentation is loading. Please wait.

ANT – Another Neat Tool Representation and Management of Data on the Internet.

Similar presentations


Presentation on theme: "ANT – Another Neat Tool Representation and Management of Data on the Internet."— Presentation transcript:

1 ANT – Another Neat Tool Representation and Management of Data on the Internet

2 What is ANT? A cross-platform build tool (like make) A scripting framework Based on industry standards (Java and XML) Open Source (development coordinated by the Apache Jakarta project)

3 What can we do with ANT? Can be used to: -compile java programs -create javadoc documentation -create jar, zip, tar, war files -delete and copy files -validate XML files -etc. (send mail, anything you want)

4 ANT Buildfiles An ANT buildfile is a file that contains the instructions for ANT’s tasks A buildfile is written in XML A buildfile has the following elements: -Project - a top level collection of targets -Property - an ANT variable -Target - a collection of tasks - Task - a unit of ANT execution (a step)

5 ANT Buildfiles property Target Task... project Target

6 Buildfile Example

7 Projects The project is the root element of the buildfile -One project per buildfile Projects can have 3 attributes: - name: name of project (optional) - default: default target to use (required) - basedir: base directory for paths (optional)

8 Properties Properties (global values) are typically defined as follows: Note: Properties are XML elements without contents, therefore we use /> A property named “ propName ” can be referred to later using the syntax: ${propName} You can define any properties you want Properties are not variable: the first value they are given remains for the whole build!

9 Special Property Definitions -sets src to the absolute file name of srcFile, taken to be relative to the project's basedir -reads a set of properties from a file called pFile -Later, you may use ${env.VAR_NAME}$ to get the system ’ s environment variable called VAR_NAME Built-in Properties (predefined): -ant.file, ant.java.version, os.name, user.name, user.home, etc …

10 Tasks A task is a piece of code to be executed The general form of a task element is ANT comes with some built-in tasks, which cover most of the basic needs for development of applications One can also define new tasks (not covered here)

11 Some Built-In Tasks Examples Directory tasks:, Archive tasks: Output tasks:

12 More Built-In Tasks Examples Java tasks: -compiles only files that need to be compiled (time based) Invoking external programs:

13 Targets A target is a collection of tasks to be performed when the target is executed Targets have the attributes: - name : name of the target (required) - depends : comma separated list of targets on which the target depends (optional) - if, unless, description : details omitted (read about it in the ANT documentation)

14 A BuildFile – Adding a Target We could also have written: A Task

15

16 <!-- Put everything in ${build} into the jar file: MyProject.jar file -->

17 More about Depends ANT tries to execute the targets in “depends” from left to right However, a target may be executed earlier when another one depends on it

18 Example 1 Execute: ant D In what order will the tasks be performed? Try DTry CTry BTry A Do DDo CDo BDo A Note: B is executed before C ! Note: B is executed once!

19 Example 2 Execute: ant A In what order will the tasks be performed? The build fails, ant reacts with: Circular dependency: A <- B <- A

20 Running ANT Type: ant ANT looks for the file: build.xml, and performs the default task specified there Use the –buildfile option to specify a different buildfile You can specify a different target to be performed You can define parameters using the –D option

21 Examples Run ANT using build.xml on the default target ant Run ANT using the test.xml file on the default target ant -buildfile test.xml Run ANT using the test.xml file on a target called dist : ant -buildfile test.xml dist Run ANT using the test.xml file on a target called dist, setting the build property to the value build/classes : ant -buildfile test.xml -Dbuild=build/classes dist

22 Make versus ANT Make: OS dependent -tasks are shell commands -Runs fast for small tasks ANT: OS independent -tasks implemented as Java classes -requires Java (≥ JDK 1.2) -Slow for small tasks – requires JVM Make: Non-standard syntax (infamous tabbing problem) ANT: XML based syntax Make: state dependencies between program files ANT: state dependencies between tasks (not between program files)

23 References To learn more about ANT: -Look at the documentation on the web (reference from the table of lecture schedule) -Pay attention to the section Built-in Tasks: there are many tasks and task parameters you might find useful


Download ppt "ANT – Another Neat Tool Representation and Management of Data on the Internet."

Similar presentations


Ads by Google