2. Why Build Scripts?
§ For large enterprise systems using the IDE is
not sufficient for building
§ Complicated Builds
§ Automatic Nightly Builds
§ Special Build Machines
§ Important to be able to separate build and
development
3.
4. What is Ant?
§ ANT is a tool to build programs
§ “make” tool
§ Uses XML file to describe the solution
§ Default file is build.xml
§ Uses Java classes to run tasks
§ Built-in tasks
§ Jakarta project
§ http://ant.apache.org
§ Current version 1.8.2
§ Installation guidelines are on the course web
5. Ant in use
Command Prompt
Verkefni>
Verkefni
build.xml
src/
ant
Buildfile: build.xml
...
Project
classes/
dist/
ANT file
Source
Class files
JAR file
Project>ant
BUILD SUCCESSFUL
Total time: 4 seconds
6. Running Ant
§ Usage
ant [options] [target [target2 [target3] ...]]
§ Target can be selected
§ Default is used if target is not specifed
§ Examples
>ant -buildfile test.xml
>ant -buildfile test.xml dist
>ant -buildfile test.xml -Dbuild=build/classes dist
7. Using Ant
§ Each build file is one project (one output)
§ Build file is XML file (for example build.xml)
§ Project has
§ Name
§ Default target
§ Basedir
§ One or more target
§ Target
<project name="MyProject"
</project>
§ Target is a collection of tasks
§ Task depend on
other tasks
default="dist"
basedir=".">
...
<target name="A"/>
<target name="B" depends="A"/>
<target name="C" depends="B"/>
<target name="D" depends="C,B,A"/>
8. Using Ant
§ Properties
§ Have names and values
<property name="dist" value="dist"/>
§ Referenced with ${property}
§ Example:
<target name="dist" depends="compile">
<mkdir dir="${dist}/lib"/>
<jar jarfile="${dist}/lib/MyProject.jar" basedir="${build}"/> </
target>
12. build.xml
<target name="compile" depends="init"
description="Compilation of all source files">
<javac srcdir="${src.java}"
destdir="${output.dir}"
classpath="${classpath}"/>
</target>
<target name="jar" depends="compile"
description="Create the JAR">
<jar jarfile="${dist.dir}/${jar.file}"
basedir="${output.dir}">
<fileset dir="${src.msg}"/>
</jar>
</target>
<target name="clean" description="Delete all generated files">
<delete dir="${output.dir}"/>
<delete dir="${dist.dir}"/>
</target>
</project>
13. Building
C:hrHonn>ant
Buildfile: build.xml
init:
[mkdir] Created dir: C:hrHonnclasses
compile:
[javac] Compiling 11 source files to C:hrHonnclasses
jar:
[jar] Building jar: C:hrHonndistImportContentProcess.jar
BUILD SUCCESSFUL
Total time: 2 seconds
C:hrHonn>java -cp libcommons-logging.jar;libjdom.jar;librome-0.8.jar;libruf
ramework.jar;libspring.jar;distImportContentProcess.jar
is.ruframework.process.RuProcessRunner
14. Using Ant with IntelliJ
§ Most IDEs support ANT
§ Must use the same
folders
§ IntelliJ has ANT support
§ Easy to use
§ Ant is powerful when
using IntelliJ to develop
container-based
programs
§ For example EJBs, Web
Apps