Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Apache Ant
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Example== A sample <code>build.xml</code> file is listed below for a simple Java "Hello, world" application. It defines four targets - <code>clean</code>,{{sfn | Moodie | 2005 | loc = Chapter Β§5 Building a Project - Assembling the project - Manipulating the File Location | pp=121-125}} <code>clobber</code>, <code>compile</code> and <code>jar</code> , each of which has an associated description. The <code>jar</code> target lists the <code>compile</code> target as a dependency. This tells Ant that before it can start the <code>jar</code> target it must first complete the <code>compile</code> target. <syntaxhighlight lang="xml"> <?xml version="1.0"?> <project name="Hello" default="compile"> <target name="clean" description="remove intermediate files"> <delete dir="classes"/> </target> <target name="clobber" depends="clean" description="remove all artifact files"> <delete file="hello.jar"/> </target> <target name="compile" description="compile the Java source code to class files"> <mkdir dir="classes"/> <javac srcdir="." destdir="classes"/> </target> <target name="jar" depends="compile" description="create a Jar file for the application"> <jar destfile="hello.jar"> <fileset dir="classes" includes="**/*.class"/> <manifest> <attribute name="Main-Class" value="HelloProgram"/> </manifest> </jar> </target> </project> </syntaxhighlight> Within each target are the actions that Ant must take to build that target; these are performed using built-in tasks. For example, to build the <code> compile </code> target Ant must first create a directory called <code>classes</code> (which Ant will do only if it does not already exist) and then invoke the Java compiler. Therefore, the tasks used are <code>mkdir</code> and <code>javac</code>. These perform a similar task to the command-line utilities of the same name. Another task used in this example is named <code>jar</code>: <syntaxhighlight lang="xml"> <jar destfile="hello.jar"> </syntaxhighlight> This Ant task has the same name as the common Java command-line utility, JAR, but is really a call to the Ant program's built-in JAR/ZIP file support. This detail is not relevant to most end users, who just get the JAR they wanted, with the files they asked for. Many Ant tasks delegate their work to external programs, either native or Java. They use Ant's own {{tag|exec|open}} and {{tag|java|open}} tasks to set up the command lines, and handle all the details of mapping from information in the build file to the program's arguments and interpreting the return value. Users can see which tasks do this (e.g. {{tag|csv|open}}, {{tag|signjar|open}}, {{tag|chmod|open}}, {{tag|rpm|open}}), by trying to execute the task on a system without the underlying program on the path, or without a full Java Development Kit (JDK) installed.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)