2001-08-07 13:51:43 +00:00
2003-01-24 08:55:06 +00:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2003-04-02 05:29:26 +00:00
< html lang = "en" >
2002-03-05 07:57:52 +00:00
<!-- GENERATED FILE, DO NOT EDIT, EDIT THE XML FILE IN xdocs INSTEAD! -->
2001-08-07 13:51:43 +00:00
< head >
2003-01-24 08:55:06 +00:00
< META http-equiv = "Content-Type" content = "text/html; charset=ISO-8859-1" >
< title > Apache Ant - Frequently Asked Questions< / title >
2003-02-10 10:46:07 +00:00
< link type = "text/css" href = "./page.css" rel = "stylesheet" >
2003-01-24 08:55:06 +00:00
< meta name = "author" content = "Stefan Bodewig" >
2003-01-21 14:30:02 +00:00
< meta name = "email" content = "bodewig@apache.org" >
2003-01-24 08:55:06 +00:00
< / head >
2003-04-02 05:29:26 +00:00
< body >
< p class = "navpath" >
< script src = "./breadcrumbs.js" language = "JavaScript" type = "text/javascript" > < / script >
< / p >
2003-01-24 08:55:06 +00:00
2003-04-04 03:58:10 +00:00
< div class = "logobar" >
< table width = "100%" border = "0" cellspacing = "0" cellpadding = "0" >
< tr >
< td align = "left" > < img border = "0" alt = "Apache Ant site" src = "./images/group-logo.gif" > < / td >
2003-04-04 04:21:04 +00:00
< td align = "center" width = "100%" > < img alt = "Apache Ant logo" border = "0" src = "./images/project-logo.gif" > < / td >
2003-04-04 03:58:10 +00:00
< td align = "right" >
< form target = "_blank" onsubmit = "q.value = query.value + ' site:ant.apache.org'" action = "http://www.google.com/search" method = "get" >
< table summary = "search" border = "0" cellspacing = "0" cellpadding = "0" bgcolor = "#4C6C8F" >
< tr >
< td colspan = "3" > < img height = "10" width = "1" alt = "" src = "./images/spacer.gif" > < / td >
< / tr >
< tr >
< td > < img height = "1" width = "1" alt = "" src = "./images/spacer.gif" > < / td >
< td nowrap = "nowrap" class = "searchcaption" >
< input name = "q" type = "hidden" >
< input size = "15" id = "query" type = "text" >
< img height = "1" width = "5" alt = "" src = "./images/spacer.gif" >
< input name = "Search" value = "Search" type = "submit" >
< br >
the Apache Ant site
< / td >
< td > < img height = "1" width = "1" alt = "" src = "./images/spacer.gif" > < / td >
< / tr >
< tr >
< td > < img alt = "" border = "0" height = "10" width = "9" src = "./images/search-left.gif" > < / td >
< td > < img height = "1" width = "1" alt = "" src = "./images/spacer.gif" > < / td >
< td > < img alt = "" border = "0" height = "10" width = "9" src = "./images/search-right.gif" > < / td >
< / tr >
< / table >
< / form >
< / td >
< / tr >
< / table >
< / div >
< div class = "tab" >
2003-01-24 08:55:06 +00:00
< table summary = "tab bar" border = "0" cellpadding = "0" cellspacing = "0" >
< tr >
2003-05-11 12:00:37 +00:00
< td width = "8" > < img alt = "" height = "5" width = "8" src = "./images/spacer.gif" > < / td > < td valign = "bottom" >
2003-02-10 10:46:07 +00:00
< table summary = "selected tab" style = "height: 1.5em" border = "0" cellpadding = "0" cellspacing = "0" >
< tr >
< td valign = "top" width = "5" bgcolor = "#4C6C8F" > < img height = "5" width = "5" alt = "" src = "./images/tabSel-left.gif" > < / td > < td valign = "middle" bgcolor = "#4C6C8F" > < font color = "#ffffff" size = "2" face = "Arial, Helvetica, Sans-serif" > < b > Home< / b > < / font > < / td > < td valign = "top" width = "5" bgcolor = "#4C6C8F" > < img height = "5" width = "5" alt = "" src = "./images/tabSel-right.gif" > < / td >
< / tr >
< / table >
< / td >
2003-02-10 23:41:10 +00:00
< td width = "5" > < img alt = "" height = "8" width = "8" src = "./images/spacer.gif" > < / td > < td valign = "bottom" >
< table summary = "non selected tab" style = "height: 1.4em" border = "0" cellpadding = "0" cellspacing = "0" >
< tr >
< td valign = "top" width = "5" bgcolor = "#B2C4E0" > < img height = "5" width = "5" alt = "" src = "./images/tab-left.gif" > < / td > < td valign = "middle" bgcolor = "#B2C4E0" > < a href = "./projects/index.html" > < font size = "2" face = "Arial, Helvetica, Sans-serif" > Projects< / font > < / a > < / td > < td valign = "top" width = "5" bgcolor = "#B2C4E0" > < img height = "5" width = "5" alt = "" src = "./images/tab-right.gif" > < / td >
< / tr >
< / table >
< / td >
< / tr >
2003-01-24 08:55:06 +00:00
< / table >
< / div >
2003-04-02 05:29:26 +00:00
2003-04-04 03:58:10 +00:00
< div class = "bluebar" > < / div >
2003-04-03 04:00:22 +00:00
< div class = "menucontainer" >
< div class = "menu" >
2003-01-24 08:55:06 +00:00
< ul >
2003-04-03 04:14:43 +00:00
< li class = "menuheader" > Apache Ant
2003-04-03 04:00:22 +00:00
< ul >
< li >
< a href = "./index.html" > Welcome< / a >
< / li >
< li >
< a href = "./license.html" > License< / a >
< / li >
< li >
< a href = "./antnews.html" > News< / a >
< / li >
< / ul >
< / li >
2003-04-03 04:14:43 +00:00
< li class = "menuheader" > Documentation
2003-04-03 04:00:22 +00:00
< ul >
< li >
< a href = "./manual/index.html" > Manual< / a >
< / li >
< li >
< a href = "./projects.html" > Related Projects< / a >
< / li >
< li >
< a href = "./external.html" > External Tools and Tasks< / a >
< / li >
< li >
< a href = "./resources.html" > Resources< / a >
< / li >
< li >
2003-04-03 04:14:43 +00:00
< span class = "sel" > Frequently Asked Questions< / span >
2003-04-03 04:00:22 +00:00
< / li >
2003-12-02 11:51:11 +00:00
< li >
2004-02-29 08:43:54 +00:00
< a href = "http://wiki.apache.org/ant/FrontPage" > Wiki< / a >
2003-12-02 11:51:11 +00:00
< / li >
2003-04-03 04:00:22 +00:00
< li >
< a href = "./problems.html" > Having Problems?< / a >
< / li >
< / ul >
< / li >
2003-04-03 04:14:43 +00:00
< li class = "menuheader" > Download
2003-04-03 04:00:22 +00:00
< ul >
< li >
< a href = "http://ant.apache.org/bindownload.cgi" > Binary Distributions< / a >
< / li >
< li >
< a href = "http://ant.apache.org/srcdownload.cgi" > Source Distributions< / a >
< / li >
< / ul >
< / li >
2003-06-25 08:10:52 +00:00
< li class = "menuheader" > Contributing
2003-04-03 04:00:22 +00:00
< ul >
< li >
< a href = "./mail.html" > Mailing Lists< / a >
< / li >
< li >
< a href = "./cvs.html" > CVS Repositories< / a >
< / li >
< li >
< a href = "http://issues.apache.org/bugzilla/enter_bug.cgi?product=Ant" > Bug Database< / a >
< / li >
< li >
< a href = "http://issues.apache.org/bugzilla/enter_bug.cgi?product=Ant&bug_severity=Enhancement" > Enhancement Requests< / a >
< / li >
2003-06-25 08:10:52 +00:00
< li >
< a href = "http://www.apache.org/foundation/contributing.html" > Donations< / a >
< / li >
2003-04-03 04:00:22 +00:00
< / ul >
< / li >
2003-04-03 04:14:43 +00:00
< li class = "menuheader" > Project Management
2003-04-03 04:00:22 +00:00
< ul >
< li >
< a href = "./contributors.html" > Contributors< / a >
< / li >
< li >
< a href = "./mission.html" > Apache Ant Mission< / a >
< / li >
2003-07-02 13:55:14 +00:00
< li >
< a href = "./bylaws.html" > Project Bylaws< / a >
< / li >
2003-04-03 04:00:22 +00:00
< li >
< a href = "./legal.html" > Legal< / a >
< / li >
< / ul >
< / li >
< / ul >
< / div >
< img style = "float: left" height = "10" width = "10" border = "0" alt = "" src = "./images/menu-left.gif" >
< img style = "float: right" height = "10" width = "10" border = "0" alt = "" src = "./images/menu-right.gif" >
2003-10-12 19:39:53 +00:00
< / div >
2003-04-04 03:58:10 +00:00
< div class = "lightbluebar" > < / div >
2003-04-09 01:44:53 +00:00
< div class = "main" >
2003-04-03 04:00:22 +00:00
< div class = "content" >
2003-04-02 08:17:38 +00:00
< h1 class = "title" > Frequently Asked Questions< / h1 >
2003-01-24 08:55:06 +00:00
2003-04-02 08:17:38 +00:00
< h3 class = "section" > Questions< / h3 >
2003-04-02 05:29:26 +00:00
< h4 class = "toc" > About this FAQ< / h4 >
2001-11-22 16:16:47 +00:00
< ul >
2003-01-24 08:55:06 +00:00
< li > < a href = "#latest-version" >
2001-11-22 16:16:47 +00:00
Where do I find the latest version of this
document?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#adding-faqs" >
2001-11-22 16:16:47 +00:00
How can I contribute to this FAQ?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#creating-faq" >
2001-11-23 12:32:07 +00:00
How do you create the HTML version of this
FAQ?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< / ul >
2003-04-02 05:29:26 +00:00
< h4 class = "toc" > General< / h4 >
2001-08-07 13:51:43 +00:00
< ul >
2003-01-24 08:55:06 +00:00
< li > < a href = "#what-is-ant" >
2001-10-30 10:05:39 +00:00
What is Apache Ant?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#ant-name" >
2001-08-07 13:51:43 +00:00
Why do you call it Ant?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#history" >
2001-08-07 13:51:43 +00:00
Tell us a little bit about Ant's history.
2003-01-24 08:55:06 +00:00
< / a > < / li >
< / ul >
2003-04-02 05:29:26 +00:00
< h4 class = "toc" > Installation< / h4 >
2001-08-07 13:51:43 +00:00
< ul >
2003-01-24 08:55:06 +00:00
< li > < a href = "#no-gnu-tar" >
2001-08-07 13:51:43 +00:00
I get checksum errors when I try to extract the
< code > tar.gz< / code > distribution file. Why?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< / ul >
2003-04-02 05:29:26 +00:00
< h4 class = "toc" > How do I ...< / h4 >
2001-08-07 13:51:43 +00:00
< ul >
2004-05-11 16:37:02 +00:00
< li > < a href = "#implement-os-specific-configuration" >
How do I realize os--specific configurations?
< / a > < / li >
2003-01-24 08:55:06 +00:00
< li > < a href = "#adding-external-tasks" >
2003-01-08 08:25:18 +00:00
How do I add an external task that I've written to the
page "External Tools and Task"?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#passing-cli-args" >
2001-08-07 13:51:43 +00:00
How do I pass parameters from the command line to my
build file?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#jikes-switches" >
2002-03-12 21:23:13 +00:00
How can I use Jikes-specific command-line
2001-08-07 13:51:43 +00:00
switches?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#shell-redirect-1" >
2002-03-12 21:23:13 +00:00
How do I include a < character in my command-line arguments?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#shell-redirect-2" >
2001-08-07 13:51:43 +00:00
How do I redirect standard input or standard output
in the < code > < exec> < / code > task?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#batch-shell-execute" >
2002-03-12 21:23:13 +00:00
How do I execute a batch file or shell script from Ant?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#multi-conditions" >
2001-11-23 12:01:35 +00:00
I want to execute a particular target only if
multiple conditions are true.
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#encoding" >
2002-10-31 13:34:48 +00:00
How can I include national characters like German
umlauts in my build file?
2003-10-13 13:42:16 +00:00
< / a > < / li >
2003-10-13 13:44:56 +00:00
< li > < a href = "#use-zip-instead-of-jar" >
2003-10-13 13:42:16 +00:00
How do I use < code > jar< / code > 's < code > M< / code > switch?
I don't want a MANIFEST.
2003-12-09 16:46:50 +00:00
< / a > < / li >
< li > < a href = "#propertyvalue-as-name-for-property" >
How can I do something like < code > < property name="prop"
value="${${anotherprop}}"/> < / code > (double expanding the property)?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< / ul >
2003-04-02 05:29:26 +00:00
< h4 class = "toc" > It doesn't work (as expected)< / h4 >
2002-10-31 13:34:48 +00:00
< ul >
2003-01-24 08:55:06 +00:00
< li > < a href = "#always-recompiles" >
2002-10-31 13:34:48 +00:00
Why does Ant always recompile all my Java files?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#defaultexcludes" >
2002-10-31 13:34:48 +00:00
I've used a < code > < delete> < / code > task to
delete unwanted SourceSafe control files (CVS files, editor
backup files, etc.), but it doesn't seem to work; the files
never get deleted. What's wrong?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#stop-dependency" >
2002-03-12 21:23:13 +00:00
I have a target I want to skip if a property is set,
2003-12-09 16:46:50 +00:00
so I have < code > unless="property"< / code > as an attribute
of the target, but all the targets this target
2001-11-23 12:01:35 +00:00
depends on are still executed. Why?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#include-order" >
2002-03-12 21:23:13 +00:00
In my < code > < fileset> < / code > , I've put in an
2001-11-23 12:01:35 +00:00
< code > < exclude> < / code > of all files followed by an
< code > < include> < / code > of just the files I want, but it
2002-03-12 21:23:13 +00:00
isn't giving me any files at all. What's wrong?
2001-11-23 12:01:35 +00:00
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#properties-not-trimmed" >
2002-09-23 12:58:01 +00:00
< code > ant< / code > failed to build my program via javac
even when I put the needed jars in an external
< code > build.properties< / code > file and reference them by
< code > pathelement< / code > or < code > classpath refid< / code > .
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#winzip-lies" >
2002-10-31 13:34:48 +00:00
Ant creates WAR files with a lower-case
< code > web-inf< / code > or JAR files with a lower-case
< code > meta-inf< / code > directory.
2004-06-28 17:00:48 +00:00
< / a > < / li >
2004-09-10 16:52:23 +00:00
< li > < a href = "#NoClassDefFoundError" >
2004-06-28 17:00:48 +00:00
I installed Ant 1.6.x and now get
< code > Exception in thread "main" java.lang.NoClassDefFoundError:
2004-09-08 09:59:13 +00:00
< / code >
< / a > < / li >
2004-09-10 16:52:23 +00:00
< li > < a href = "#InstantiationException" >
2004-09-08 09:59:13 +00:00
I installed Ant 1.6.x and now get
< code > java.lang.InstantiationException: org.apache.tools.ant.Main< / code >
2004-06-28 17:00:48 +00:00
2003-01-24 08:55:06 +00:00
< / a > < / li >
< / ul >
2003-04-02 05:29:26 +00:00
< h4 class = "toc" > Ant and IDEs/Editors< / h4 >
2001-08-07 13:51:43 +00:00
< ul >
2003-01-24 08:55:06 +00:00
< li > < a href = "#integration" >
2001-08-07 13:51:43 +00:00
Is Ant supported by my IDE/Editor?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#emacs-mode" >
2001-08-07 13:51:43 +00:00
Why doesn't (X)Emacs/vi/MacOS X's project builder
2002-03-12 21:23:13 +00:00
correctly parse the error messages generated by Ant?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< / ul >
2003-04-02 05:29:26 +00:00
< h4 class = "toc" > Advanced Issues< / h4 >
2001-08-07 13:51:43 +00:00
< ul >
2003-01-24 08:55:06 +00:00
< li > < a href = "#dtd" >
2001-08-07 13:51:43 +00:00
Is there a DTD that I can use to validate my build
files?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#xml-entity-include" >
2001-08-07 13:51:43 +00:00
How do I include an XML snippet in my build file?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#mail-logger" >
2001-08-07 13:51:43 +00:00
How do I send an email with the result of my build
process?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#listener-properties" >
2001-11-23 12:01:35 +00:00
How do I get at the properties that Ant was running
with from inside BuildListener?
2003-01-24 08:55:06 +00:00
< / a > < / li >
< / ul >
2003-04-02 05:29:26 +00:00
< h4 class = "toc" > Known Problems< / h4 >
2001-08-07 13:51:43 +00:00
< ul >
2003-01-24 08:55:06 +00:00
< li > < a href = "#remove-cr" >
2002-03-12 21:23:13 +00:00
< chmod> or < exec> doesn't work in Ant
2001-08-07 13:51:43 +00:00
1.3 on Unix
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#javadoc-cannot-execute" >
2001-08-07 13:51:43 +00:00
JavaDoc failed: java.io.IOException: javadoc: cannot execute
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#delegating-classloader" >
2002-04-18 14:48:13 +00:00
< style> or < junit> ignores my
< classpath>
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#winxp-jdk14-ant14" >
2002-09-23 12:50:07 +00:00
When running Ant 1.4 on Windows XP and JDK 1.4, I get
various errors when trying to < code > < exec> < / code > , fork
< code > < java> < / code > or access environment
variables.
2003-01-24 08:55:06 +00:00
< / a > < / li >
< li > < a href = "#1.5-cygwin-sh" >
2002-07-15 11:45:35 +00:00
The < code > ant< / code > wrapper script of Ant 1.5 fails
for Cygwin if < code > ANT_HOME< / code > is set to a Windows style
path.
2003-04-08 13:04:24 +00:00
< / a > < / li >
< li > < a href = "#1.5.2-zip-broken" >
< code > < zip> < / code > is broken in Ant 1.5.2.
2004-02-18 16:01:14 +00:00
< / a > < / li >
< li > < a href = "#unknownelement.taskcontainer" >
Why do my custom task containers see Unknown Elements in Ant 1.6
- they worked in Ant 1.5?
2004-03-15 11:23:48 +00:00
< / a > < / li >
< li > < a href = "#java.exception.stacktrace" >
The program I run via < java> throws an exception but I
can't seem to get the full stack trace.
2004-04-20 07:27:21 +00:00
< / a > < / li >
< li > < a href = "#junit-no-runtime-xml" >
Using format="xml", < junit> fails with a
< code > NoClassDefFoundError< / code > if forked.
2004-06-02 12:31:18 +00:00
< / a > < / li >
< li > < a href = "#xalan-jdk1.5" >
< code > < junitreport> < / code > doesn't work with JDK 1.5 but
worked fine with JDK 1.4.
2003-01-24 08:55:06 +00:00
< / a > < / li >
< / ul >
2003-04-02 08:17:38 +00:00
< h3 class = "section" > Answers< / h3 >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "latest-version" > < / a >
2003-04-02 05:29:26 +00:00
Where do I find the latest version of this
2001-11-22 16:16:47 +00:00
document?
2003-04-02 05:29:26 +00:00
< / p >
2003-12-09 16:46:50 +00:00
< p > The latest version can always be found at Ant's homepage
2003-01-24 08:55:06 +00:00
< a href = "http://ant.apache.org/faq.html" > http://ant.apache.org/faq.html< / a > .< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "adding-faqs" > < / a >
2003-04-02 05:29:26 +00:00
How can I contribute to this FAQ?
< / p >
2003-12-09 16:46:50 +00:00
< p > The page you are looking it is generated from
2003-02-10 11:00:36 +00:00
< a href = "http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/faq.xml" > this< / a >
2001-11-22 16:16:47 +00:00
document. If you want to add a new question, please submit
2002-03-12 21:23:13 +00:00
a patch against this document to one of Ant's mailing lists;
hopefully, the structure is self-explanatory.< / p >
2003-01-24 08:55:06 +00:00
< p > If you don't know how to create a patch, see the patches
2001-11-23 12:01:35 +00:00
section of < a href = "http://jakarta.apache.org/site/source.html" > this
page< / a > .< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "creating-faq" > < / a >
2003-04-02 05:29:26 +00:00
How do you create the HTML version of this
2001-11-23 12:32:07 +00:00
FAQ?
2003-04-02 05:29:26 +00:00
< / p >
2003-12-09 16:46:50 +00:00
< p > We use
2001-11-23 12:32:07 +00:00
< a href = "http://jakarta.apache.org/velocity/anakia.html" > Anakia< / a >
to render the HTML version from the original XML file.< / p >
2003-01-24 08:55:06 +00:00
< p > The Velocity stylesheets used to process the XML files can
2001-11-23 12:32:07 +00:00
be found in the < code > xdocs/stylesheets< / code > subdirectory of
2003-01-13 13:24:07 +00:00
Ant's CVS repository - the build file
2003-02-10 13:49:25 +00:00
< code > docs.xml< / code > at the top level of the ant CVS
2003-01-13 13:24:07 +00:00
module is used to drive Anakia.< / p >
2003-01-24 08:55:06 +00:00
< p > This file assumes that you have the
2003-01-13 13:24:07 +00:00
< code > jakarta-site2< / code > CVS module checked out as well, but
if you follow the instruction from Anakia's homepage, you
should get it to work without that. Just make sure all
required jars are in the task's classpath.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "what-is-ant" > < / a >
2003-04-02 05:29:26 +00:00
What is Apache Ant?
< / p >
2003-01-24 08:55:06 +00:00
< p > Ant is a Java-based build tool. In theory, it is kind of
2002-03-12 21:23:13 +00:00
like Make, without Make's wrinkles and with the full
2001-08-07 13:51:43 +00:00
portability of pure Java code.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "ant-name" > < / a >
2003-04-02 05:29:26 +00:00
Why do you call it Ant?
< / p >
2003-01-24 08:55:06 +00:00
< p > According to Ant's original author, James Duncan
2001-08-07 13:51:43 +00:00
Davidson, the name is an acronym for "Another Neat
Tool".< / p >
2003-12-09 16:46:50 +00:00
< p > Later explanations go along the lines of "ants
2002-03-12 21:23:13 +00:00
do an extremely good job at building things", or
"ants are very small and can carry a weight dozens of times
their own" - describing what Ant is intended to
2001-08-07 13:51:43 +00:00
be.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "history" > < / a >
2003-04-02 05:29:26 +00:00
Tell us a little bit about Ant's history.
< / p >
2003-01-24 08:55:06 +00:00
< p > Initially, Ant was part of the Tomcat code base, when it was
2002-03-12 21:23:13 +00:00
donated to the Apache Software Foundation. It was
created by James Duncan Davidson, who is also the original
2001-08-07 13:51:43 +00:00
author of Tomcat. Ant was there to build Tomcat, nothing
else.< / p >
2003-01-24 08:55:06 +00:00
< p > Soon thereafter, several open source Java projects realized
2002-03-12 21:23:13 +00:00
that Ant could solve the problems they had with Makefiles.
2001-08-07 13:51:43 +00:00
Starting with the projects hosted at Jakarta and the old Java
2002-03-12 21:23:13 +00:00
Apache project, Ant spread like a virus and is now the build
2001-08-07 13:51:43 +00:00
tool of choice for a lot of projects.< / p >
2003-01-24 08:55:06 +00:00
< p > In January 2000, Ant was moved to a separate CVS module and
2001-08-07 13:51:43 +00:00
was promoted to a project of its own, independent of
2002-03-12 21:23:13 +00:00
Tomcat, and became Apache Ant.< / p >
2003-01-24 08:55:06 +00:00
< p > The first version of Ant that was exposed to a larger audience
2001-08-07 13:51:43 +00:00
was the one that shipped with Tomcat's 3.1 release on 19 April
2002-03-12 21:23:13 +00:00
2000. This version has later been referred to as Ant
2001-08-07 13:51:43 +00:00
0.3.1.< / p >
2003-01-24 08:55:06 +00:00
< p > The first official release of Ant as a stand-alone product was
2002-03-12 21:23:13 +00:00
Ant 1.1, released on 19 July 2000. The complete release
2001-08-07 13:51:43 +00:00
history:< / p >
2003-07-03 08:33:53 +00:00
< table class = "ForrestTable" cellspacing = "1" cellpadding = "4" >
2001-08-07 13:51:43 +00:00
< tr >
2003-01-24 08:55:06 +00:00
< th colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
Ant Version
2003-01-24 08:55:06 +00:00
< / th >
< th colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
Release Date
2003-01-24 08:55:06 +00:00
< / th >
2001-08-07 13:51:43 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
1.1
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
19 July 2000
2003-01-24 08:55:06 +00:00
< / td >
2001-08-07 13:51:43 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
1.2
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
24 October 2000
2003-01-24 08:55:06 +00:00
< / td >
2001-08-07 13:51:43 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
1.3
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
3 March 2001
2003-01-24 08:55:06 +00:00
< / td >
2001-09-10 11:20:48 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-09-10 11:20:48 +00:00
valign="top" align="left">
1.4
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-09-10 11:20:48 +00:00
valign="top" align="left">
3 September 2001
2003-01-24 08:55:06 +00:00
< / td >
2001-10-11 13:44:42 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-10-11 13:44:42 +00:00
valign="top" align="left">
1.4.1
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-10-11 13:44:42 +00:00
valign="top" align="left">
11 October 2001
2003-01-24 08:55:06 +00:00
< / td >
2002-07-10 14:38:51 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2002-07-10 14:38:51 +00:00
valign="top" align="left">
1.5
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2002-07-10 14:38:51 +00:00
valign="top" align="left">
10 July 2002
2003-01-24 08:55:06 +00:00
< / td >
2002-10-03 14:37:00 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2002-10-03 14:37:00 +00:00
valign="top" align="left">
1.5.1
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2002-10-03 14:37:00 +00:00
valign="top" align="left">
3 October 2002
2003-01-24 08:55:06 +00:00
< / td >
2003-03-03 15:24:14 +00:00
< / tr >
< tr >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
1.5.2
< / td >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
3 March 2003
< / td >
2003-04-14 19:28:14 +00:00
< / tr >
< tr >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
1.5.3
< / td >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
9 April 2003
< / td >
2003-08-13 06:11:58 +00:00
< / tr >
< tr >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
1.5.4
< / td >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
12 August 2003
< / td >
2003-12-18 21:47:06 +00:00
< / tr >
< tr >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
1.6.0
< / td >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
18 December 2003
< / td >
2004-02-12 13:56:06 +00:00
< / tr >
< tr >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
1.6.1
< / td >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
12 February 2004
< / td >
2004-07-16 09:30:51 +00:00
< / tr >
< tr >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
1.6.2
< / td >
< td colspan = "1" rowspan = "1"
valign="top" align="left">
16 July 2004
< / td >
2001-08-07 13:51:43 +00:00
< / tr >
< / table >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "no-gnu-tar" > < / a >
2003-04-02 05:29:26 +00:00
I get checksum errors when I try to extract the
2001-08-07 13:51:43 +00:00
< code > tar.gz< / code > distribution file. Why?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > Ant's distribution contains file names that are longer
2001-08-07 13:51:43 +00:00
than 100 characters, which is not supported by the standard
tar file format. Several different implementations of tar use
different and incompatible ways to work around this
restriction.< / p >
2003-01-24 08:55:06 +00:00
< p > Ant's < tar> task can create tar archives that use
2001-08-07 13:51:43 +00:00
the GNU tar extension, and this has been used when putting
together the distribution. If you are using a different
version of tar (for example, the one shipping with Solaris),
you cannot use it to extract the archive.< / p >
2003-01-24 08:55:06 +00:00
< p > The solution is to either install GNU tar, which can be
2002-03-12 21:23:13 +00:00
found < a href = "http://www.gnu.org/software/tar/tar.html" > here< / a > ,
2001-08-07 13:51:43 +00:00
or use the zip archive instead (you can extract it using
< code > jar xf< / code > ).< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2004-05-11 16:37:02 +00:00
< a name = "implement-os-specific-configuration" > < / a >
How do I realize os--specific configurations?
< / p >
< p > The core idea is using property files which name accords to the
os-name. Then simply use the build-in property < tt > os.name< / tt > .< / p >
< p > For better use you should also provide a file with defaul values.
But be careful with the correct os-names. For test simply < echo>
the ${os.name} on all machines and you can be sure to use the right
file names.< / p >
< pre class = "code" >
< property file=" ${os.name}.properties" />
< property file=" default.properties" />
< / pre >
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "adding-external-tasks" > < / a >
2003-04-02 05:29:26 +00:00
How do I add an external task that I've written to the
2003-01-08 08:25:18 +00:00
page "External Tools and Task"?
2003-04-02 05:29:26 +00:00
< / p >
2003-02-19 08:45:17 +00:00
< p > Join and post a message to the dev or user mailing
2003-01-08 08:25:18 +00:00
list (one list is enough), including the following
information:< / p >
2003-01-24 08:55:06 +00:00
< ul >
2003-01-08 08:25:18 +00:00
< li > the name of the task/tool< / li >
< li > a short description of the task/tool< / li >
< li > a Compatibility: entry stating with which version(s) of
Ant the tool/task is compatible to< / li >
< li > a URL: entry linking to the main page of the tool/task< / li >
< li > a Contact: entry containing the email address or the URL
of a webpage for the person or list to contact for issues
related to the tool/task. < strong > Note that we'll add a
link on the page, so any email address added there is not
obfuscated and can (and probably will) be abused by robots
harvesting websites for addresses to spam.< / strong > < / li >
< li > a License: entry containing the type of license for the
tool/task< / li >
< / ul >
2003-02-10 13:49:25 +00:00
< p > The preferred format for this information is a patch to < a href = "http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/external.xml" > this< / a >
2003-01-08 08:25:18 +00:00
document.< / p >
2004-05-11 16:37:02 +00:00
< p > If you have written something bigger than a 'simple plugin' to Ant it
may be better to add the link to < a href = "projects.html" > projects.html< / a > .
The procedure to add it is the same. The file to patch is < a href = "http://cvs.apache.org/viewcvs.cgi/~checkout~/ant/xdocs/projects.xml" > this< / a >
document. The syntax of that file is the same.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "passing-cli-args" > < / a >
2003-04-02 05:29:26 +00:00
How do I pass parameters from the command line to my
2001-08-07 13:51:43 +00:00
build file?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > Use properties. Using < code > ant
2002-03-12 21:23:13 +00:00
-D< em > name< / em > =< em > value< / em > < / code > lets you define values for
properties on the Ant command line. These properties can then be
used within your build file as
any normal property: < code > ${< em > name< / em > }< / code > will put in
< code > < em > value< / em > < / code > .< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "jikes-switches" > < / a >
2003-04-02 05:29:26 +00:00
How can I use Jikes-specific command-line
2001-08-07 13:51:43 +00:00
switches?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > A couple of switches are supported via "magic"
2001-08-07 13:51:43 +00:00
properties:< / p >
2003-07-03 08:33:53 +00:00
< table class = "ForrestTable" cellspacing = "1" cellpadding = "4" >
2001-08-07 13:51:43 +00:00
< tr >
2003-01-24 08:55:06 +00:00
< th colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
switch
2003-01-24 08:55:06 +00:00
< / th >
< th colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
property
2003-01-24 08:55:06 +00:00
< / th >
< th colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
default
2003-01-24 08:55:06 +00:00
< / th >
2001-08-07 13:51:43 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
+E
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
build.compiler.emacs
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
false == not set
2003-01-24 08:55:06 +00:00
< / td >
2001-08-07 13:51:43 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
2001-08-30 13:19:03 +00:00
+P
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
2001-08-30 13:19:03 +00:00
build.compiler.pedantic
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
2001-08-30 13:19:03 +00:00
false == not set
2003-01-24 08:55:06 +00:00
< / td >
2001-08-07 13:51:43 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
2001-08-30 13:19:03 +00:00
+F
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
2001-08-30 13:19:03 +00:00
build.compiler.fulldepend
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
false == not set
2003-01-24 08:55:06 +00:00
< / td >
2001-08-07 13:51:43 +00:00
< / tr >
< tr >
2003-01-24 08:55:06 +00:00
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
2002-03-12 21:23:13 +00:00
< strong > (Only for Ant < 1.4; replaced by the
< code > < strong > nowarn< / strong > < / code >
attribute of the < code > < strong > < javac> < / strong > < / code >
task after that.)< / strong > < br / > -nowarn
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
2001-08-30 13:19:03 +00:00
build.compiler.warnings
2003-01-24 08:55:06 +00:00
< / td >
< td colspan = "1" rowspan = "1"
2001-08-07 13:51:43 +00:00
valign="top" align="left">
2001-08-30 13:19:03 +00:00
true == not set
2003-01-24 08:55:06 +00:00
< / td >
2001-08-07 13:51:43 +00:00
< / tr >
< / table >
2003-01-24 08:55:06 +00:00
< p > With Ant > = 1.5, you can also use nested
2002-07-30 15:00:40 +00:00
< code > < compilerarg> < / code > elements with the
< code > < javac> < / code > task.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "shell-redirect-1" > < / a >
2003-04-02 05:29:26 +00:00
How do I include a < character in my command-line arguments?
< / p >
2003-01-24 08:55:06 +00:00
< p > The short answer is "Use: < code > & lt;< / code > ".< / p >
< p > The long answer is that this probably won't do what you
2002-03-12 21:23:13 +00:00
want anyway (see < a href = "#shell-redirect-2" > the next
section< / a > ).< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "shell-redirect-2" > < / a >
2003-04-02 05:29:26 +00:00
How do I redirect standard input or standard output
2001-08-07 13:51:43 +00:00
in the < code > < exec> < / code > task?
2003-04-02 05:29:26 +00:00
< / p >
2003-08-14 16:16:21 +00:00
< p > Say you want to redirect the standard output stream of the
< code > m4< / code > command to write to a file, something
2002-03-12 21:23:13 +00:00
like:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2003-08-14 16:16:21 +00:00
shell-prompt> m4 foo.m4 > foo
2003-01-24 08:55:06 +00:00
< / pre >
< p > and try to translate it into< / p >
< pre class = "code" >
2003-08-14 16:16:21 +00:00
< exec executable=" m4" >
< arg value=" foo.m4" />
< arg value=" & gt;" />
< arg value=" foo" />
2001-08-07 13:51:43 +00:00
< /exec>
2003-01-24 08:55:06 +00:00
< / pre >
2003-08-14 16:16:21 +00:00
< p > This will not do what you expect. The output redirection is
2001-08-07 13:51:43 +00:00
performed by your shell, not the command itself, so this
should read:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-08-07 13:51:43 +00:00
< exec executable=" /bin/sh" >
< arg value=" -c" />
2003-08-14 16:16:21 +00:00
< arg value=" m4 foo.m4 & gt; foo" />
2001-08-07 13:51:43 +00:00
< /exec>
2003-01-24 08:55:06 +00:00
< / pre >
< p > Note that you must use the < code > value< / code > attribute of
2002-03-12 21:23:13 +00:00
< code > < arg> < / code > in the last element, in order to have
the command passed as a single, quoted argument. Alternatively,
you can use:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2002-03-12 21:23:13 +00:00
< exec executable=" /bin/sh" >
2003-08-14 16:16:21 +00:00
< arg line='-c " m4 foo.m4 & gt; foo" '/>
2002-03-12 21:23:13 +00:00
< /exec>
2003-01-24 08:55:06 +00:00
< / pre >
< p > Note the double-quotes nested inside the single-quotes.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "batch-shell-execute" > < / a >
2003-04-02 05:29:26 +00:00
How do I execute a batch file or shell script from Ant?
< / p >
2003-01-24 08:55:06 +00:00
< p > On native Unix systems, you should be able to run shell scripts
2002-03-13 17:02:35 +00:00
directly. On systems running a Unix-type shell (for example, Cygwin
on Windows) execute the (command) shell instead - < code > cmd< / code >
for batch files, < code > sh< / code > for shell scripts - then pass the
batch file or shell script (plus any arguments to the script)
as a single command, using the < code > /c< / code > or
2002-03-12 21:23:13 +00:00
< code > -c< / code > switch, respectively. See
< a href = "#shell-redirect-2" > the above section< / a >
for example < code > < exec> < / code > tasks
2002-03-13 17:02:35 +00:00
executing < code > sh< / code > . For batch files, use something like:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2002-03-13 17:02:35 +00:00
< exec dir=" ." executable=" cmd" os=" Windows NT" >
2002-03-12 21:23:13 +00:00
< arg line=" /c test.bat" />
< /exec>
2003-01-24 08:55:06 +00:00
< / pre >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "multi-conditions" > < / a >
2003-04-02 05:29:26 +00:00
I want to execute a particular target only if
2001-11-23 12:01:35 +00:00
multiple conditions are true.
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > There are actually several answers to this question.< / p >
< p > If you have only one set and one unset property to test,
2002-03-12 21:23:13 +00:00
you can specify both an < code > if< / code > and an < code > unless< / code >
attribute for the target, and they will act as if they
2001-11-23 12:01:35 +00:00
are "anded" together.< / p >
2003-01-24 08:55:06 +00:00
< p > If you are using a version of Ant 1.3 or earlier, the
2001-11-23 12:01:35 +00:00
way to work with all other cases is to chain targets together
2002-03-12 21:23:13 +00:00
to determine the specific state you want to test for.< / p >
2003-01-24 08:55:06 +00:00
< p > To see how this works, assume you have three properties:
2001-11-23 12:01:35 +00:00
< code > prop1< / code > , < code > prop2< / code > , and < code > prop3< / code > .
2003-12-09 16:46:50 +00:00
You want to test that < code > prop1< / code > and < code > prop2< / code >
2002-03-12 21:23:13 +00:00
are set, and that < code > prop3< / code > is not. If the condition
2001-11-23 12:01:35 +00:00
holds true you want to echo "yes".< / p >
2003-01-24 08:55:06 +00:00
< p > Here is the implementation in Ant 1.3 and earlier:< / p >
< pre class = "code" >
2001-11-23 12:01:35 +00:00
< target name=" cond" depends=" cond-if" />
< target name=" cond-if" if=" prop1" >
< antcall target=" cond-if-2" />
< /target>
< target name=" cond-if-2" if=" prop2" >
< antcall target=" cond-if-3" />
< /target>
< target name=" cond-if-3" unless=" prop3" >
< echo message=" yes" />
< /target>
2003-01-24 08:55:06 +00:00
< / pre >
< p > Note: < code > < antcall> < / code > tasks do < em > not< / em > pass
2001-11-23 12:01:35 +00:00
property changes back up to the environment they were called
2002-03-12 21:23:13 +00:00
from, so you would'nt be able to, for example, set a
< code > result< / code > property in the < code > cond-if-3< / code > target,
then do
< code > < echo message="result is ${result}"/> < / code >
in the < code > cond< / code > target.< / p >
2003-01-24 08:55:06 +00:00
< p > Starting with Ant 1.4, you can use the
2001-11-23 12:01:35 +00:00
< code > < condition> < / code > task.< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-11-23 12:01:35 +00:00
< target name=" cond" depends=" cond-if,cond-else" />
< target name=" check-cond" >
< condition property=" cond-is-true" >
< and>
< not>
< equals arg1=" ${prop1}" arg2=" $${prop1}" />
< /not>
< not>
< equals arg1=" ${prop2}" arg2=" $${prop2}" />
< /not>
< equals arg1=" ${prop3}" arg2=" $${prop3}" />
< /and>
< /condition>
< /target>
< target name=" cond-if" depends=" check-cond" if=" cond-is-true" >
< echo message=" yes" />
< /target>
< target name=" cond-else" depends=" check-cond" unless=" cond-is-true" >
< echo message=" no" />
< /target>
2003-01-24 08:55:06 +00:00
< / pre >
< p > This version takes advantage of two things:< / p >
< ul >
2001-11-23 12:01:35 +00:00
< li > If a property < code > a< / code > has not been set,
< code > ${a}< / code > will evaluate to < code > ${a}< / code > .< / li >
< li > To get a literal < code > $< / code > in Ant, you have to
escape it with another < code > $< / code > - this will also break
2002-03-12 21:23:13 +00:00
the special treatment of the < code > ${< / code > sequence.< / li >
2001-11-23 12:01:35 +00:00
< / ul >
2003-01-24 08:55:06 +00:00
< p > Because testing for a literal < code > ${property}< / code > string
2002-03-12 21:23:13 +00:00
isn't all that readable or easy to understand,
2003-12-09 16:46:50 +00:00
post-1.4.1 Ant introduces the < code > < isset> < / code > element
to the < code > < condition> < / code > task.< / p >
2003-01-24 08:55:06 +00:00
< p > Here is the previous example done using
2001-11-23 12:01:35 +00:00
< code > < isset> < / code > :< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-11-23 12:01:35 +00:00
< target name=" check-cond" >
< condition property=" cond-is-true" >
< and>
< isset property=" prop1" />
< isset property=" prop2" />
< not>
< isset property=" prop3" />
< /not>
< /and>
< /condition>
< /target>
2003-01-24 08:55:06 +00:00
< / pre >
< p > The last option is to use a scripting language to set the
2001-11-23 12:01:35 +00:00
properties. This can be particularly handy when you need much
2002-03-12 21:23:13 +00:00
finer control than the simple conditions shown here but, of
course, comes with the overhead of adding JAR files to support
2001-11-23 12:01:35 +00:00
the language, to say nothing of the added maintenance in requiring
2002-03-12 21:23:13 +00:00
two languages to implement a single system. See the
< a href = "manual/OptionalTasks/script.html" >
< code > < script> < / code > task documentation< / a > for more
details.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "encoding" > < / a >
2003-04-02 05:29:26 +00:00
How can I include national characters like German
2002-10-31 13:34:48 +00:00
umlauts in my build file?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > You need to tell the XML parser which character encoding
2002-10-31 13:34:48 +00:00
your build file uses, this is done inside the < a href = "http://www.w3.org/TR/2000/REC-xml-20001006#sec-prolog-dtd" > XML
declaration< / a > .< / p >
2003-01-24 08:55:06 +00:00
< p > By default the parser assumes you are using the UTF-8
2002-10-31 13:34:48 +00:00
encoding instead of your platform's default. For most Western
European countries you should set the encoding to
< code > ISO-8859-1< / code > . To do so, make the very first line
of you build file read like< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2002-10-31 13:34:48 +00:00
< ?xml version=" 1.0" encoding=" ISO-8859-1" ?>
2003-01-24 08:55:06 +00:00
< / pre >
2003-10-13 13:42:16 +00:00
< p class = "faq" >
2003-10-13 13:44:56 +00:00
< a name = "use-zip-instead-of-jar" > < / a >
2003-10-13 13:42:16 +00:00
How do I use < code > jar< / code > 's < code > M< / code > switch?
I don't want a MANIFEST.
< / p >
< p > A JAR archive is a ZIP file, so if you don't want a
MANIFEST you can simply use < code > < zip> < / code > .< / p >
2003-10-13 13:44:56 +00:00
< p > If your file names contain national characters you should
2003-10-13 13:42:16 +00:00
know that Sun's < code > jar< / code > utility like Ant's
< code > < jar> < / code > uses UFT8 to encode their names while
< code > < zip> < / code > uses your platforms default encoding.
Use the encoding attribute of < code > < zip> < / code > if
necessary.< / p >
2003-12-09 16:46:50 +00:00
< p class = "faq" >
< a name = "propertyvalue-as-name-for-property" > < / a >
How can I do something like < code > < property name="prop"
value="${${anotherprop}}"/> < / code > (double expanding the property)?
< / p >
< p > Without any external help you can not.< / p >
< p > With < script/> , which needs external libraries, you can do< / p >
< pre class = "code" >
< script language=" javascript" >
propname = project.getProperty(" anotherprop" );
project.setNewProperty(" prop" , propname);
< /script>
< / pre >
< p > With AntContrib (external task library) you can do < code >
< propertycopy name="prop" from="${anotherprop}"/> < / code > .< / p >
2004-04-14 06:40:08 +00:00
< p > With Ant 1.6 you can simulate the AntContribs < propertycopy>
and avoid the need of an external library:< / p >
< pre class = "code" >
< macrodef name=" propertycopy" >
< attribute name=" name" />
< attribute name=" from" />
< sequential>
< property name=" @{name}" value=" ${@{from}}" />
< /sequential>
< /macrodef>
< / pre >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "always-recompiles" > < / a >
2003-04-02 05:29:26 +00:00
Why does Ant always recompile all my Java files?
< / p >
2003-01-24 08:55:06 +00:00
< p > In order to find out which files should be compiled, Ant
2002-10-31 13:34:48 +00:00
compares the timestamps of the source files to those of the
resulting < code > .class< / code > files. Opening all source files
to find out which package they belong to would be very
inefficient. Instead, Ant expects you to place your
source files in a directory hierarchy that mirrors your
package hierarchy and to point Ant to the root of this
directory tree with the < code > srcdir< / code > attribute.< / p >
2003-01-24 08:55:06 +00:00
< p > Say you have < code > < javac srcdir="src"
2002-10-31 13:34:48 +00:00
destdir="dest"/> < / code > . If Ant finds a file
< code > src/a/b/C.java< / code > , it expects it to be in package
< code > a.b< / code > so that the resulting < code > .class< / code >
file is going to be < code > dest/a/b/C.class< / code > .< / p >
2003-01-24 08:55:06 +00:00
< p > If your source-tree directory structure does not match your
2002-10-31 13:34:48 +00:00
package structure, Ant's heuristic won't work, and
it will recompile classes that are up-to-date. Ant is not the
only tool that expects a source-tree layout like this.< / p >
2003-01-24 08:55:06 +00:00
< p > If you have Java source files that aren't declared to
2002-10-31 13:34:48 +00:00
be part of any package, you can still use the < code > < javac> < / code >
task to compile these files correctly - just set the
< code > srcdir< / code > and < code > destdir< / code > attributes to
the actual directory the source
files live in and the directory the class files should go into,
respectively.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "defaultexcludes" > < / a >
2003-04-02 05:29:26 +00:00
I've used a < code > < delete> < / code > task to
2002-10-31 13:34:48 +00:00
delete unwanted SourceSafe control files (CVS files, editor
backup files, etc.), but it doesn't seem to work; the files
never get deleted. What's wrong?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > This is probably happening because, by default, Ant excludes
2002-10-31 13:34:48 +00:00
SourceSafe control files (< code > vssver.scc< / code > ) and certain other
files from FileSets.< / p >
2003-01-24 08:55:06 +00:00
< p > Here's what you probably did:< / p >
< pre class = "code" >
2002-10-31 13:34:48 +00:00
< delete>
< fileset dir=" ${build.src}" includes=" **/vssver.scc" />
< /delete>
2003-01-24 08:55:06 +00:00
< / pre >
< p > You need to switch off the default exclusions,
2002-10-31 13:34:48 +00:00
and it will work:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2002-10-31 13:34:48 +00:00
< delete>
< fileset dir=" ${build.src}" includes=" **/vssver.scc"
defaultexcludes=" no" />
< /delete>
2003-01-24 08:55:06 +00:00
< / pre >
< p > For a complete listing of the patterns that are excluded
2002-10-31 13:34:48 +00:00
by default, see < a href = "manual/dirtasks.html#defaultexcludes" > the user
manual< / a > .< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "stop-dependency" > < / a >
2003-04-02 05:29:26 +00:00
I have a target I want to skip if a property is set,
2003-12-09 16:46:50 +00:00
so I have < code > unless="property"< / code > as an attribute
of the target, but all the targets this target
2001-11-23 12:01:35 +00:00
depends on are still executed. Why?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > The list of dependencies is generated by Ant before any of the
2003-12-09 16:46:50 +00:00
targets are run. This allows dependent targets, such as an
< code > init< / code > target, to set properties that can control the
execution of the targets higher in the dependency graph. This
is a good thing.< / p >
2003-01-24 08:55:06 +00:00
< p > However, when your dependencies break down the
2002-03-12 21:23:13 +00:00
higher-level task
2003-12-09 16:46:50 +00:00
into several smaller steps, this behaviour becomes
2002-03-12 21:23:13 +00:00
counter-intuitive. There are a couple of solutions available:
2001-11-23 12:01:35 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< ol >
2001-11-23 12:01:35 +00:00
< li > Put the same condition on each of the dependent targets.< / li >
2003-12-09 16:46:50 +00:00
2002-03-12 21:23:13 +00:00
< li > Execute the steps using < code > < antcall> < / code > ,
2001-11-23 12:01:35 +00:00
instead of specifying them inside the < code > depends< / code >
attribute.< / li >
< / ol >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "include-order" > < / a >
2003-04-02 05:29:26 +00:00
In my < code > < fileset> < / code > , I've put in an
2001-11-23 12:01:35 +00:00
< code > < exclude> < / code > of all files followed by an
< code > < include> < / code > of just the files I want, but it
2002-03-12 21:23:13 +00:00
isn't giving me any files at all. What's wrong?
2001-11-23 12:01:35 +00:00
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > The order of the < code > < include> < / code > and
2002-03-12 21:23:13 +00:00
< code > < exclude> < / code > tags within a < code > < fileset> < / code >
is ignored when the FileSet is created. Instead, all of the
2001-11-23 12:01:35 +00:00
< code > < include> < / code > elements are processed together,
followed by all of the < code > < exclude> < / code >
elements. This means that the < code > < exclude> < / code >
elements only apply to the file list produced by the
< code > < include> < / code > elements.< / p >
2003-01-24 08:55:06 +00:00
< p > To get the files you want, focus on just the
2003-12-09 16:46:50 +00:00
< code > < include> < / code > patterns that would be necessary
to get them. If you find you need to trim the list that the
< code > < include> < / code > elements produce, then use
< code > < exclude> < / code > elements.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "properties-not-trimmed" > < / a >
2003-04-02 05:29:26 +00:00
< code > ant< / code > failed to build my program via javac
2002-10-31 13:34:48 +00:00
even when I put the needed jars in an external
< code > build.properties< / code > file and reference them by
< code > pathelement< / code > or < code > classpath refid< / code > .
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > When < code > ant< / code > loads properties from an external
2002-10-31 13:34:48 +00:00
file it dosn't touch the value of properties, trailing blanks
will not be trimmed for example.< / p >
2003-01-24 08:55:06 +00:00
< p > If the value represents a file path, like a jar needed to
2002-10-31 13:34:48 +00:00
compile, the task which requires the value, javac for example
would fail to compile since it can't find the file due to
trailing spaces.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "winzip-lies" > < / a >
2003-04-02 05:29:26 +00:00
Ant creates WAR files with a lower-case
2002-10-31 13:34:48 +00:00
< code > web-inf< / code > or JAR files with a lower-case
< code > meta-inf< / code > directory.
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > No it doesn't.< / p >
< p > You may have seen these lower-case directory names in
2002-10-31 13:34:48 +00:00
WinZIP, but WinZIP is trying to be helpful (and fails). If
WinZIP encounters a filename that is all upper-case, it
2003-10-13 15:29:52 +00:00
assumes it has come from an old DOS box and changes the case to
2002-10-31 13:34:48 +00:00
all lower-case for you.< / p >
2003-01-24 08:55:06 +00:00
< p > If you extract (or just check) the archive with jar, you
2002-10-31 13:34:48 +00:00
will see that the names have the correct case.< / p >
2003-08-20 16:07:48 +00:00
< p > With WinZIP (version 8.1 at least), this can be corrected in the
configuration. In the Options/Configuration menu, in the View tab, General
section, check the "Allow all upper case files names" box. The META-INF and
WEB-INF will look correct.< / p >
2004-06-28 17:00:48 +00:00
< p class = "faq" >
2004-09-10 16:52:23 +00:00
< a name = "NoClassDefFoundError" > < / a >
2004-06-28 17:00:48 +00:00
I installed Ant 1.6.x and now get
< code > Exception in thread "main" java.lang.NoClassDefFoundError:
2004-09-08 09:59:13 +00:00
< / code >
< / p >
< p >
The cause of this is that there is an old version of ant somewhere in the
class path or configuration.
< / p >
< p >
A version of this problem happens with jars that are in the classpath
that include an embedded copy of ant classes.
An example of this is some copies of weblogic.jar.
2004-09-08 10:05:36 +00:00
< / p >
< p >
One can check if this is the case by doing (on unix/sh):
< code > < pre >
unset CLASSPATH
ant -version
< / pre >
< / code >
2004-09-08 09:59:13 +00:00
< / p >
< p class = "faq" >
2004-09-10 16:52:23 +00:00
< a name = "InstantiationException" > < / a >
2004-09-08 09:59:13 +00:00
I installed Ant 1.6.x and now get
< code > java.lang.InstantiationException: org.apache.tools.ant.Main< / code >
2004-06-28 17:00:48 +00:00
< / p >
< p >
The cause of this is that there is an old version of ant somewhere in the
class path or configuration.
< / p >
< p >
A version of this problem may be seen on some linux systems.
Some linux systems (Fedora Core 2 for example), comes with a version
of ant pre-installed. There is a configuration file called
< code > /etc/ant.conf< / code > which if present, the ant shell
script will 'dot' include. On Fedora Core 2, the /etc/ant.conf
file resets the < code > ANT_HOME< / code > environment variable to
< code > /usr/share/ant< / code > . This causes the problem that
an old version of ant (1.5.x in this cause) will be used
with a new version of the ant script file.
< / p >
< p >
One can check if this is the case by doing
< code > ant --noconfig -version< / code > .
< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "integration" > < / a >
2003-04-02 05:29:26 +00:00
Is Ant supported by my IDE/Editor?
< / p >
2003-12-09 16:46:50 +00:00
< p > See the < a href = "external.html#IDE and Editor Integration" > section
2002-03-12 21:23:13 +00:00
on IDE integration< / a > on our External Tools and Tasks page.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "emacs-mode" > < / a >
2003-04-02 05:29:26 +00:00
Why doesn't (X)Emacs/vi/MacOS X's project builder
2002-03-12 21:23:13 +00:00
correctly parse the error messages generated by Ant?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > Ant adds a "banner" with the name of the current
2002-03-12 21:23:13 +00:00
task in front of all logging messages - and there are no built-in
regular expressions in your editor that would account for
2001-08-07 13:51:43 +00:00
this.< / p >
2003-01-24 08:55:06 +00:00
< p > You can disable this banner by invoking Ant with the
2002-07-30 14:52:10 +00:00
< code > -emacs< / code > switch. To make Ant autodetect
Emacs' compile mode, put this into your
< code > .antrc< / code > (contributed by Ville Skytt<74> ).< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2002-07-30 14:52:10 +00:00
# Detect (X)Emacs compile mode
2003-12-09 16:46:50 +00:00
if [ " $EMACS" = " t" ] ; then
ANT_ARGS=" $ANT_ARGS -emacs"
ANT_OPTS=" $ANT_OPTS -Dbuild.compiler.emacs=true"
fi
2003-01-24 08:55:06 +00:00
< / pre >
< p > Alternatively, you can add the following snippet to your
2002-07-30 14:52:10 +00:00
< code > .emacs< / code > to make Emacs understand Ant's
output.< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-08-07 13:51:43 +00:00
(require 'compile)
(setq compilation-error-regexp-alist
2003-12-09 16:46:50 +00:00
(append (list
2001-08-07 13:51:43 +00:00
;; works for jikes
'(" ^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):\\([0-9]+\\):[0-9]+:[0-9]+:" 1 2 3)
2003-12-09 16:46:50 +00:00
;; works for javac
2001-08-07 13:51:43 +00:00
'(" ^\\s-*\\[[^]]*\\]\\s-*\\(.+\\):\\([0-9]+\\):" 1 2))
compilation-error-regexp-alist))
2003-01-24 08:55:06 +00:00
< / pre >
< p > Yet another alternative that preserves most of Ant's
2001-08-07 13:51:43 +00:00
formatting is to pipe Ant's output through the following Perl
script by Dirk-Willem van Gulik:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-08-07 13:51:43 +00:00
#!/usr/bin/perl
#
# May 2001 dirkx@apache.org - remove any
# [foo] lines from the output; keeping
# spacing more or less there.
#
$|=1;
while(< STDIN> ) {
2003-12-09 16:46:50 +00:00
if (s/^(\s+)\[(\w+)\]//) {
if ($2 ne $last) {
print " $1\[$2\]" ;
$s = ' ' x length($2);
} else {
print " $1 $s " ;
};
$last = $2;
};
print;
2001-08-07 13:51:43 +00:00
};
2003-01-24 08:55:06 +00:00
< / pre >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "dtd" > < / a >
2003-04-02 05:29:26 +00:00
Is there a DTD that I can use to validate my build
2001-08-07 13:51:43 +00:00
files?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > An incomplete DTD can be created by the
2001-08-07 13:51:43 +00:00
< code > < antstructure> < / code > task - but this one
has a few problems:< / p >
2003-01-24 08:55:06 +00:00
< ul >
2001-08-07 13:51:43 +00:00
< li > It doesn't know about required attributes. Only
manual tweaking of this file can help here.< / li >
2003-12-09 16:46:50 +00:00
2001-08-07 13:51:43 +00:00
< li > It is not complete - if you add new tasks via
< code > < taskdef> < / code > it won't know about it. See
< a href = "http://www.sdv.fr/pages/casa/html/ant-dtd.en.html" > this
page< / a > by Michel Casabianca for a solution to this
problem. Note that the DTD you can download at this page
is based on Ant 0.3.1.< / li >
< li > It may even be an invalid DTD. As Ant allows tasks
writers to define arbitrary elements, name collisions will
happen quite frequently - if your version of Ant contains
the optional < code > < test> < / code > and
< code > < junit> < / code > tasks, there are two XML
2002-03-12 21:23:13 +00:00
elements named < code > test< / code > (the task and the nested child
element of < code > < junit> < / code > ) with different attribute
lists. This problem cannot be solved; DTDs don't give a
2001-08-07 13:51:43 +00:00
syntax rich enough to support this.< / li >
< / ul >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "xml-entity-include" > < / a >
2003-04-02 05:29:26 +00:00
How do I include an XML snippet in my build file?
< / p >
2003-01-24 08:55:06 +00:00
< p > You can use XML's way of including external files and let
2001-08-07 13:51:43 +00:00
the parser do the job for Ant:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-08-07 13:51:43 +00:00
< ?xml version=" 1.0" ?>
< !DOCTYPE project [
< !ENTITY common SYSTEM " file:./common.xml" >
]>
< project name=" test" default=" test" basedir=" ." >
< target name=" setup" >
...
< /target>
& common;
...
< /project>
2003-01-24 08:55:06 +00:00
< / pre >
< p > will literally include the contents of < code > common.xml< / code > where
2001-08-07 13:51:43 +00:00
you've placed the < code > & common;< / code > entity.< / p >
2003-01-24 08:55:06 +00:00
< p > In combination with a DTD, this would look like this:< / p >
< pre class = "code" >
2001-08-07 13:51:43 +00:00
< !DOCTYPE project PUBLIC " -//ANT//DTD project//EN" " file:./ant.dtd" [
< !ENTITY include SYSTEM " file:./header.xml" >
]>
2003-01-24 08:55:06 +00:00
< / pre >
2003-10-13 13:18:08 +00:00
< p > Starting with Ant 1.6, there is a new
< code > < import> < / code > task that can (also) be used to
include build file fragments. Unlike the snippets used with
entity includes, the referenced files have to be complete Ant
build files, though.< / p >
< p > The example above would become:< / p >
< pre class = "code" >
< ?xml version=" 1.0" ?>
< project name=" test" default=" test" basedir=" ." >
< target name=" setup" >
...
< /target>
2004-01-08 17:01:27 +00:00
< import file=" ./common.xml" />
2003-10-13 13:18:08 +00:00
...
< /project>
< / pre >
< p > Unlike entity includes, < code > < import> < / code > will
let you use Ant properties in the file name.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "mail-logger" > < / a >
2003-04-02 05:29:26 +00:00
How do I send an email with the result of my build
2001-08-07 13:51:43 +00:00
process?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > If you are using a nightly build of Ant 1.5 after
2002-03-12 21:23:13 +00:00
2001-12-14, you can use the built-in MailLogger:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-12-14 12:28:01 +00:00
ant -logger org.apache.tools.ant.listener.MailLogger
2003-01-24 08:55:06 +00:00
< / pre >
2003-02-10 13:49:25 +00:00
< p > See the < a href = "http://cvs.apache.org/viewcvs/~checkout~/ant/docs/manual/listeners.html?content-type=text/html" > Listeners
2002-03-12 21:23:13 +00:00
& Loggers< / a > documentation for details on the properties
2001-12-14 12:28:01 +00:00
required.< / p >
2003-01-24 08:55:06 +00:00
< p > For older versions of Ant, you can use a custom
2002-03-12 21:23:13 +00:00
BuildListener that sends out an email
2001-08-07 13:51:43 +00:00
in the buildFinished() method. Will Glozer
< will.glozer@jda.com> has written such a listener based
2003-12-09 16:46:50 +00:00
on < a href = "http://java.sun.com/products/javamail/" > JavaMail< / a > .
2002-03-12 21:23:13 +00:00
The source is:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-08-07 13:51:43 +00:00
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import org.apache.tools.ant.*;
/**
* A simple listener that waits for a build to finish and sends an email
* of the results. The settings are stored in " monitor.properties" and
* are fairly self explanatory.
*
* @author Will Glozer
* @version 1.05a 09/06/2000
*/
public class BuildMonitor implements BuildListener {
protected Properties props;
/**
* Create a new BuildMonitor.
*/
public BuildMonitor() throws Exception {
props = new Properties();
InputStream is = getClass().getResourceAsStream(" monitor.properties" );
props.load(is);
is.close();
}
public void buildStarted(BuildEvent e) {
}
/**
* Determine the status of the build and the actions to follow, now that
* the build has completed.
*
2002-07-30 15:00:40 +00:00
* @param e Event describing the build status.
2001-08-07 13:51:43 +00:00
*/
public void buildFinished(BuildEvent e) {
Throwable th = e.getException();
String status = (th != null) ? " failed" : " succeeded" ;
2003-12-09 16:46:50 +00:00
2001-08-07 13:51:43 +00:00
try {
String key = " build." + status;
if (props.getProperty(key + " .notify" ).equalsIgnoreCase(" false" )) {
return;
}
2003-12-09 16:46:50 +00:00
2001-08-07 13:51:43 +00:00
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
message.addRecipients(Message.RecipientType.TO, parseAddresses(
props.getProperty(key + " .email.to" )));
message.setSubject(props.getProperty(key + " .email.subject" ));
BufferedReader br = new BufferedReader(new FileReader(
props.getProperty(" build.log" )));
StringWriter sw = new StringWriter();
2003-12-09 16:46:50 +00:00
2001-08-07 13:51:43 +00:00
String line = br.readLine();
while (line != null) {
sw.write(line);
sw.write(" \n" );
line = br.readLine();
}
br.close();
2003-12-09 16:46:50 +00:00
2001-08-07 13:51:43 +00:00
message.setText(sw.toString(), " UTF-8" );
sw.close();
2003-12-09 16:46:50 +00:00
2001-08-07 13:51:43 +00:00
Transport transport = session.getTransport();
transport.connect();
transport.send(message);
transport.close();
} catch (Exception ex) {
System.out.println(" BuildMonitor failed to send email!" );
ex.printStackTrace();
}
}
/**
* Parse a comma separated list of internet email addresses.
*
* @param s The list of addresses.
* @return Array of Addresses.
*/
protected Address[] parseAddresses(String s) throws Exception {
StringTokenizer st = new StringTokenizer(s, " ," );
Address[] addrs = new Address[st.countTokens()];
for (int i = 0; i < addrs.length; i++) {
addrs[i] = new InternetAddress(st.nextToken());
}
return addrs;
}
public void messageLogged(BuildEvent e) {
}
public void targetStarted(BuildEvent e) {
}
public void targetFinished(BuildEvent e) {
}
2003-12-09 16:46:50 +00:00
public void taskStarted(BuildEvent e) {
2001-08-07 13:51:43 +00:00
}
public void taskFinished(BuildEvent e) {
}
}
2003-01-24 08:55:06 +00:00
< / pre >
< p > With a < code > monitor.properties< / code > like this:< / p >
< pre class = "code" >
2001-08-07 13:51:43 +00:00
# configuration for build monitor
mail.transport.protocol=smtp
mail.smtp.host=< host>
mail.from=Will Glozer < will.glozer@jda.com>
build.log=build.log
build.failed.notify=true
build.failed.email.to=will.glozer@jda.com
build.failed.email.subject=Nightly build failed!
build.succeeded.notify=true
build.succeeded.email.to=will.glozer@jda.com
build.succeeded.email.subject=Nightly build succeeded!
2003-01-24 08:55:06 +00:00
< / pre >
< p > < code > monitor.properties< / code > should be placed right next
2001-08-07 13:51:43 +00:00
to your compiled < code > BuildMonitor.class< / code > . To use it,
2002-03-12 21:23:13 +00:00
invoke Ant like:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-12-13 12:04:56 +00:00
ant -listener BuildMonitor -logfile build.log
2003-01-24 08:55:06 +00:00
< / pre >
< p > Make sure that < code > mail.jar< / code > from JavaMail and
2003-12-09 16:46:50 +00:00
< code > activation.jar< / code > from the
2001-08-07 13:51:43 +00:00
< a href = "http://java.sun.com/products/javabeans/glasgow/jaf.html" > Java
2002-03-12 21:23:13 +00:00
Beans Activation Framework< / a > are in your < code > CLASSPATH< / code > .< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "listener-properties" > < / a >
2003-04-02 05:29:26 +00:00
How do I get at the properties that Ant was running
2001-11-23 12:01:35 +00:00
with from inside BuildListener?
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > You can get at a hashtable with all the properties that Ant
2001-11-23 12:01:35 +00:00
has been using through the BuildEvent parameter. For
example:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-11-23 12:01:35 +00:00
public void buildFinished(BuildEvent e) {
Hashtable table = e.getProject().getProperties();
String buildpath = (String)table.get(" build.path" );
...
}
2003-01-24 08:55:06 +00:00
< / pre >
< p > This is more accurate than just reading the same property
2001-11-23 12:01:35 +00:00
files that your project does, since it will give the correct
2002-03-12 21:23:13 +00:00
results for properties that were specified on the Ant command line.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "remove-cr" > < / a >
2003-04-02 05:29:26 +00:00
< chmod> or < exec> doesn't work in Ant
2001-08-07 13:51:43 +00:00
1.3 on Unix
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > The < code > antRun< / code > script in < code > ANT_HOME/bin< / code >
2002-03-12 21:23:13 +00:00
has DOS instead of Unix line endings; you must remove the
carriage-return characters from this file. This can be done by
using Ant's < code > < fixcrlf> < / code > task
or something like:< / p >
2003-01-24 08:55:06 +00:00
< pre class = "code" >
2001-08-07 13:51:43 +00:00
tr -d '\r' < $ANT_HOME/bin/antRun > /tmp/foo
mv /tmp/foo $ANT_HOME/bin/antRun
2003-01-24 08:55:06 +00:00
< / pre >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "javadoc-cannot-execute" > < / a >
2003-04-02 05:29:26 +00:00
JavaDoc failed: java.io.IOException: javadoc: cannot execute
< / p >
2003-01-24 08:55:06 +00:00
< p > There is a bug in the Solaris reference implementation of
2002-03-12 21:23:13 +00:00
the JDK (see < a href = "http://developer.java.sun.com/developer/bugParade/bugs/4230399.html" > http://developer.java.sun.com/developer/bugParade/bugs/4230399.html< / a > ).
This also appears to be true under Linux. Moving the JDK to
2001-08-07 13:51:43 +00:00
the front of the PATH fixes the problem.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "delegating-classloader" > < / a >
2003-04-02 05:29:26 +00:00
< style> or < junit> ignores my
2002-04-18 14:48:13 +00:00
< classpath>
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > These tasks don't ignore your classpath setting, you
2002-04-18 14:48:13 +00:00
are facing a common problem with delegating classloaders.< / p >
2003-01-24 08:55:06 +00:00
< p > First of all let's state that Ant adds all
2002-04-18 14:48:13 +00:00
< code > .jar< / code > files from < code > ANT_HOME/lib< / code > to
< code > CLASSPATH< / code > , therefore "in
< code > CLASSPATH< / code > " shall mean "either in your
< code > CLASSPATH< / code > environment variable or
< code > ANT_HOME/lib< / code > " for the rest of this
answer.< / p >
2003-10-07 14:28:25 +00:00
< p > Technically the sentence above isn't true for Ant 1.6
and later anymore, but the result is the same. For the sake
of this discussion, < code > CLASSPATH< / code > and
< code > ANT_HOME/lib< / code > are identical.< / p >
2003-01-24 08:55:06 +00:00
< p > This question collects a common type of problem: A task
2002-04-18 14:48:13 +00:00
needs an external library and it has a nested classpath
element so that you can point it to this external library, but
that doesn't work unless you put the external library into the
< code > CLASSPATH< / code > .< / p >
2003-01-24 08:55:06 +00:00
< p > The root of the problem is that the class that needs the
2002-04-18 14:48:13 +00:00
external library is on the < code > CLASSPATH< / code > .< / p >
2003-01-24 08:55:06 +00:00
< p > When you specify a nested < code > < classpath> < / code > in
2002-04-18 14:48:13 +00:00
Ant, Ant creates a new class loader that uses the path you
have specified. It then tries to load additional classes from
this classloader.< / p >
2003-01-24 08:55:06 +00:00
< p > In most cases - for example the two cases above - Ant
2002-04-18 14:48:13 +00:00
doesn't load the external library directly, it is the loaded
class that does so.< / p >
2003-01-24 08:55:06 +00:00
< p > In the case of < code > < junit> < / code > it is the task
2002-04-18 14:48:13 +00:00
implementation itself and in the case of
< code > < style> < / code > it is the implementation of the
< code > org.apache.tools.ant.taskdefs.XSLTLiaison< / code >
class.< / p >
2003-01-24 08:55:06 +00:00
< p > Ant's class loader implementation uses Java's
2002-04-18 14:48:13 +00:00
delegation model, see < a href = "http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html" > http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ClassLoader.html< / a >
the paragraph< / p >
2003-01-24 08:55:06 +00:00
< blockquote > The < code > ClassLoader< / code > class uses a
2002-04-18 14:48:13 +00:00
delegation model to search for classes and resources. Each
instance of < code > ClassLoader< / code > has an associated parent
class loader. When called upon to find a class or resource, a
< code > ClassLoader< / code > instance will delegate the search for
the class or resource to its parent class loader before
attempting to find the class or resource itself. The virtual
machine's built-in class loader, called the bootstrap
class loader, does not itself have a parent but may serve as
the parent of a < code > ClassLoader< / code >
instance.< / blockquote >
2003-01-24 08:55:06 +00:00
< p > This means, Ant's class loader will consult the
2002-04-18 14:48:13 +00:00
bootstrap class loader first, which tries to load classes from
< code > CLASSPATH< / code > . The bootstrap class loader
doesn't know anything about Ant's class loader or
even the path you have specified.< / p >
2003-01-24 08:55:06 +00:00
< p > If the bootstrap class loader can load the class Ant has
2002-04-18 14:48:13 +00:00
asked it to load, this class will try to load the external
library from < code > CLASSPATH< / code > as well - it doesn't
know anything else - and will not find it unless the library
is in < code > CLASSPATH< / code > as well.< / p >
2003-01-24 08:55:06 +00:00
< p > To solve this, you have two major options:< / p >
< ol >
2002-07-30 15:00:40 +00:00
< li > put all external libraries you need in
2002-04-18 14:48:13 +00:00
< code > CLASSPATH< / code > as well this is not what you want,
otherwise you wouldn't have found this FAQ entry.< / li >
< li > remove the class that loads the external library from
the < code > CLASSPATH< / code > .< / li >
< / ol >
2003-10-07 14:28:25 +00:00
< p > < strong > Using The Second Option with Ant 1.5.4 and
Earlier:< / strong > < / p >
2003-01-24 08:55:06 +00:00
< p > The easiest way to do this is to remove
2002-04-18 14:48:13 +00:00
< code > optional.jar< / code > from < code > ANT_HOME/lib< / code > . If
you do so, you will have to < code > < taskdef> < / code > all
optional tasks and use nested < code > < classpath> < / code >
elements in the < code > < taskdef> < / code > tasks that point
to the new location of < code > optional.jar< / code > . Also,
don't forget to add the new location of
< code > optional.jar< / code > to the
< code > < classpath> < / code > of your
< code > < style> < / code > or < code > < junit> < / code >
task.< / p >
2003-01-24 08:55:06 +00:00
< p > If you want to avoid to < code > < taskdef> < / code > all
2002-04-18 14:48:13 +00:00
optional tasks you need, the only other option is to remove
the classes that should not be loaded via the bootstrap class
loader from < code > optional.jar< / code > and put them into a
separate archive. Add this separate archive to the
< code > < classpath> < / code > of your
< code > < style> < / code > or < code > < junit> < / code > task
- and make sure the separate archive is not in
< code > CLASSPATH< / code > .< / p >
2003-01-24 08:55:06 +00:00
< p > In the case of < code > < junit> < / code > you'd have
2002-04-18 14:48:13 +00:00
to remove all classes that are in the
< code > org/apache/tools/ant/taskdefs/optional/junit< / code >
directory, in the < code > < style> < / code > case it is one of
the < code > *Liaison< / code > classes in
< code > org/apache/tools/ant/taskdefs/optional< / code > .< / p >
2003-10-07 14:28:25 +00:00
< p > < strong > Using The Second Option with Ant 1.6 and
later:< / strong > < / p >
< p > In Ant 1.6 < code > optional.jar< / code > has been split into
multiple jars, each one containing classes with the same
dependencies on external libraries. You can move the
"offending" jar out of ANT_HOME/lib. For the
< code > < junit> < / code > task it would be
< code > ant-junit.jar< / code > and for < code > < style> < / code >
it would be < code > ant-trax.jar< / code > ,
< code > ant-xalan1.jar< / code > or < code > ant-xslp.jar< / code > -
depending on the processor you use.< / p >
2003-01-24 08:55:06 +00:00
< p > If you use the option to break up < code > optional.jar< / code >
2003-10-07 14:28:25 +00:00
for < code > < junit> < / code > or remove
< code > ant-junit.jar< / code > , you still have to use a
2002-04-18 14:48:13 +00:00
< code > < taskdef> < / code > with a nested
< code > < classpath> < / code > to define the junit task.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "winxp-jdk14-ant14" > < / a >
2003-04-02 05:29:26 +00:00
When running Ant 1.4 on Windows XP and JDK 1.4, I get
2002-09-23 12:50:07 +00:00
various errors when trying to < code > < exec> < / code > , fork
< code > < java> < / code > or access environment
variables.
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > Ant < 1.5 doesn't recognize Windows XP as a flavor
2002-09-23 12:50:07 +00:00
of Windows that runs < code > CMD.EXE< / code > instead of
< code > COMMAND.COM< / code > . JDK 1.3 will tell Ant that Windows
XP is Windows 2000 so the problem doesn't show up
there.< / p >
2003-01-24 08:55:06 +00:00
< p > Apart from upgrading to Ant 1.5 or better, setting the
2002-09-23 12:50:07 +00:00
environment variable < code > ANT_OPTS< / code > to
< code > -Dos.name=Windows_NT< / code > prior to invoking Ant has
been confirmed as a workaround.< / p >
2003-04-02 05:29:26 +00:00
< p class = "faq" >
2003-01-24 08:55:06 +00:00
< a name = "1.5-cygwin-sh" > < / a >
2003-04-02 05:29:26 +00:00
The < code > ant< / code > wrapper script of Ant 1.5 fails
2002-07-15 11:45:35 +00:00
for Cygwin if < code > ANT_HOME< / code > is set to a Windows style
path.
2003-04-02 05:29:26 +00:00
< / p >
2003-01-24 08:55:06 +00:00
< p > This problem has been reported only hours after Ant 1.5 has
2003-02-10 12:35:11 +00:00
been released, see < a href = "http://issues.apache.org/bugzilla/show_bug.cgi?id=10664" > Bug
2003-04-08 13:04:24 +00:00
10664< / a > and all its duplicates.< / p >
2003-02-10 11:00:36 +00:00
< p > A fixed version of the wrapper script can be found < a href = "http://ant.apache.org/old-releases/v1.5/errata/" > here< / a > .
2002-07-15 11:45:35 +00:00
Simply replace your script with this version.< / p >
2003-04-08 13:04:24 +00:00
< p class = "faq" >
< a name = "1.5.2-zip-broken" > < / a >
< code > < zip> < / code > is broken in Ant 1.5.2.
< / p >
< p > Yes, it is.< / p >
< p > The problem reported by most people - see < a href = "http://issues.apache.org/bugzilla/show_bug.cgi?id=17648" > Bug
17648< / a > and all its duplicates - is that Ant creates
archives that a partially unreadable by WinZIP. Luckily
< code > jar< / code > deals with the archives and so the generated
jars/wars/ears will most likely work for you anyway.< / p >
< p > There are additional problems, see bugs < a href = "http://issues.apache.org/bugzilla/show_bug.cgi?id=17780" > Bug
17780< / a > , < a href = "http://issues.apache.org/bugzilla/show_bug.cgi?id=17871" > Bug
17871< / a > and < a href = "http://issues.apache.org/bugzilla/show_bug.cgi?id=18403" > Bug
18403< / a > . All of them are supposed to be fixed with Ant
1.5.3 (and only 18403 should exist in 1.5.3beta1).< / p >
2004-02-18 16:01:14 +00:00
< p class = "faq" >
< a name = "unknownelement.taskcontainer" > < / a >
Why do my custom task containers see Unknown Elements in Ant 1.6
- they worked in Ant 1.5?
< / p >
< p >
The objects added in TaskContainer.addTask(Task task)
have changed from Tasks to UnknownElements.
< / p >
< p >
There was a number of valid reasons for this change. But the backward
2004-02-19 12:45:03 +00:00
compatibility problems were not noticed until after Ant 1.6.0 was
2004-02-18 16:01:14 +00:00
released.
< / p >
< p >
Your container class will need to be modified to check if the Task
is an UnknownElement and call perform on it to
convert it to a Task and to execute it.
(see apache.tools.ant.taskdefs.Sequential)
< / p >
< p >
If you want to do more processing on the task,
you need to use the techniques in apache.tools.ant.taskdefs.Antlib#execute()
This does make use of one 1.6 method call (UE#getRealObject()),
2004-02-19 12:45:03 +00:00
you need to use UE#getTask() instead - this will
2004-02-18 16:01:14 +00:00
return null for non tasks (types like fileset id=x).
< / p >
< p >
2004-02-19 12:45:03 +00:00
So.. iterate over the tasks, if they are UEs, convert them to
2004-02-18 16:01:14 +00:00
tasks, using UE#maybeConfigure and UE#getTask()
< / p >
< pre class = "code" >
for (Iterator i = tasks.iterator(); i.hasNext();) {
Task t = (Task) i.next();
if (t instanceof UnknownElement) {
((UnknownElement) t).maybeConfigure();
t = ((UnknownElement) t).getTask();
if (t == null) {
continue;
}
}
// .... original Custom code
}
< / pre >
< p >
This approach should work for ant1.5 and ant1.6.
< / p >
2004-03-15 11:23:48 +00:00
< p class = "faq" >
< a name = "java.exception.stacktrace" > < / a >
The program I run via < java> throws an exception but I
can't seem to get the full stack trace.
< / p >
< p > This is a know bug that has been fixed after the release of
Ant 1.6.1.< / p >
< p > As a workaround, run your < java> task with
< code > fork="true"< / code > and Ant will display the full
trace.< / p >
2004-04-20 07:27:21 +00:00
< p class = "faq" >
< a name = "junit-no-runtime-xml" > < / a >
Using format="xml", < junit> fails with a
< code > NoClassDefFoundError< / code > if forked.
< / p >
< p > The XML formatter needs the < a href = "http://www.w3.org/DOM/" > DOM classes< / a > to work. If you
are using JDK 1.4 or later they are included with your Java
Runtime and this problem won't occur. If you are running JDK
1.3 or earlier, the DOM classes have to be on your
< junit> task's < classpath> .< / p >
< p > Prior to Ant 1.6.0 Ant would include the DOM classes from
the XML parser that is used by Ant itself if you set the
includeAntRuntime attribute to true (the default). With Ant
1.6.0 this has been changed as this behavior made it
impossible to use a different XML parser in your tests.< / p >
< p > This means that you have to take care of the DOM classes
explicitly starting with Ant 1.6.0. If you don't need to set
up a different XML parser for your tests, the easiest solution
is to add< / p >
< pre class = "code" >
< pathelement path=" ${ant.home}/lib/xml-apis.jar:${ant.home}/lib/xercesImpl.jar" />
< / pre >
< p > to your task's < classpath> .< / p >
2004-06-02 12:31:18 +00:00
< p class = "faq" >
< a name = "xalan-jdk1.5" > < / a >
< code > < junitreport> < / code > doesn't work with JDK 1.5 but
worked fine with JDK 1.4.
< / p >
< p > While JDK 1.4.x contains a version of Xalan-J 2, JDK 1.5
(and later?) have < a href = "http://java.sun.com/j2se/1.5.0/compatibility.html#4959783" > moved
to XSLTC< / a > . Since this task uses Xalan's redirect
extensions for its internal stylesheet, Ant doesn't support
XSLTC yet. This means that you have to install < a href = "http://xml.apache.org/xalan-j/" > Xalan-J 2< / a > in order
to use this task with JDK 1.5.< / p >
2004-06-25 13:42:10 +00:00
< p > Starting with Ant 1.6.2 < code > < junitreport> < / code >
2004-07-28 07:41:44 +00:00
supports JDK 1.5.< / p >
2003-01-24 08:55:06 +00:00
< / div >
2003-04-09 01:44:53 +00:00
< / div >
2003-04-03 04:00:22 +00:00
< p class = "copyright" >
2004-01-07 07:28:00 +00:00
Copyright © 2000-2004 The Apache Software Foundation. All rights reserved.
2003-04-03 00:41:29 +00:00
< script type = "text/javascript" language = "JavaScript" > < ! - -
document.write(" - "+"Last Published: " + document.lastModified);
// -->
< / script >
< / p >
2001-08-07 13:51:43 +00:00
< / body >
< / html >
2003-01-24 08:55:06 +00:00
2001-08-07 13:51:43 +00:00
2004-06-16 14:25:36 +00:00