You don’t need to deal with the different :; classpath conventions or /\ conventions in different platforms.
You can extend ANT with Java code that uses the ANT classes and interfaces.
Normally ANT just feeds all the source files to javac.exe, invoking it only once. This makes it far faster than java.exe compilation for compiling many directories. If you use the DEPEND function it will delete some class files before doing this to force Java to recompile based on dependencies. I have heard conflicting reports on whether it will catch all the recompilations needed. Adding JAVAMAKE to ANT makes is slightly smarter, but it still cannot be relied on to catch all the files that need recompiling. It is conservative, and recompiles even more than it needs to when a static final changes. Whenever you change static finals in ANT, you had better recompile the universe doing a clean compile by deleting all the class files first.
SET ANT_HOME=E:\apache-ant-1.7.0I found that sometimes ANT could not find its own classfiles. I solved this by copying all its jars to the java ext directory. ANT requires that the environment variable JAVA_HOME be set correctly to J:\Program Files\java\jdk1.6.0_06.
rem build with ANT under CygWin Bash rem -v = verbose rem -Duser.home=W: = set System property user.home to W: rem -f build2.xml = use ANT script build2.xml (default is build.xml) rem build = run the "build" target ant -v -Duser.home=cygdrive/w -f build2.xml build
// conditional increment in Java if ( file.exists() ) i++;You had to write: Then you have some idea of the verbosity of ANT conditionals. Obviously, ANT conditionals are not written in Java, but they have that same degree of awkwardness. This comes from trying to do everything in pure XML syntax. In ANT you have to create a named step called a target that contains the commands you may or may not want to execute. Then you apply the keyword if and property name to the target. You have to elsewhere in the program set the property to true or false depending on whether you want the step executed. Then you have to do an <antcall to the step to attempt to execute it! All this, because the ANT people have a love affair with XML! It is major production to conditionally copy a file that may or may not exist.
The ANT people tend to set up directory structures like this: C:\project7\source\com\mindprod\holidays for the *.java files and C:\project7\build\classes\com\mindprod\holidays for the *.class files.
If you do things the Antish way, then the basedir is C:\project7.
If you insist on doing things the simpler way with classes and source in the same directory and you have a simple directory structure like this C:\com\mindprod\holidays for both *.java and *.class, then your basedir is C:\.
The basedir defaults to the current directory when ANT was invoked. This is rarely what you want. When you use a meta-ANT script to invoke all your little build.xml scripts using <ANT or <subant, it can set, and believe it or not, even override the setting in the individual build.xml scripts.
Though I don’t see ANT experts doing this, it seems logical you should explicitly specify the basedir in each xml script. Examples often show it as . or *.*. To me, this makes no sense. Then the script only works if you put the build.xml in the basedir and cd to the basedir before you start the script.
Beware the index="true" option on <jar. At least turn it off if Java can’t find your classes. The problem has been reported in older ANT versions when you have a manifest Class-Path entry. If you set it to true, you must include additional jars using the indexjars feature.
Javish has the following advantages:
<property name="srcdir" value="source"/>Further javac is not smart enough to automatically look in the srcdir property. You have to explicitly feed it the srcdir property with a command like this: If you define srcdir as a relative directory name, it is relative to basedir, not the current directory. Setting it to . means it is the same as the basedir.
Now where should srcdir point? It depends just how much you want to recompile. Let’s assume you just want to compile the classes in the com.mindprod.holidays package.
If you do things the antish way, srcdir should point to C:\project7\source\com\mindprod\holidays where the *.java files you want to compile are.
If you do things the simple way with *.java and *.class mixed then srcdir should point to C:\com\mindprod\holidays.
Let’s assume you want to recompile every java source in the entire com tree.
If you do things the antish way, srcdir should point to C:\project7\source\com,
If you do things the simple way with *.java and *.class mixed then srcdir should point to C:\com.
If you do things the simple way with *.java and *.class mixed then destdir should point to C:\, or just leave it out, and javac will automatically put class files in the same directory as the corresponding source file.
<property name="classes.dir" value="${basedir}/classes"/>
You debug once, not once for each package. Either everything works or nothing works. This is important because debugging ANT scripts is difficult. ANT gives you very little explanation of why it does what it does and the documentation is abysmal. You have to figure most things out by experiment or by looking at other people’s scripts.
![]() |
recommend book⇒Ant in Action | |||||||||||||||||
| paperback | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 1-932394-80-X | |||||||||||||||||
| ISBN13: | 978-1-932394-80-1 | |||||||||||||||||
| publisher: | Manning | |||||||||||||||||
| published: | 2007-07-12 | |||||||||||||||||
| by: | Steve Loughran and Erik Hatcher | |||||||||||||||||
| Convert JUnit and extending the core tasks. This is not just a repackaging of the ANT documentation. | ||||||||||||||||||
| ||||||||||||||||||
![]() |
recommend book⇒Pro Apache Ant | |||||||||||||||||
| hardcover | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 1-59059-559-9 | |||||||||||||||||
| ISBN13: | 978-1-59059-559-6 | |||||||||||||||||
| publisher: | Apress | |||||||||||||||||
| published: | 2005-11-16 | |||||||||||||||||
| by: | Matthew Moodie | |||||||||||||||||
| Step by step examples. | ||||||||||||||||||
| ||||||||||||||||||
![]() |
recommend book⇒Ant: The Definitive Guide | |||||||||||||||||||||
| paperback | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ISBN10: | 0-596-00184-3 | |||||||||||||||||||||
| ISBN13: | 978-0-596-00184-1 | |||||||||||||||||||||
| publisher: | O’Reilly | |||||||||||||||||||||
| published: | 2002-05-15 | |||||||||||||||||||||
| by: | Jesse E. Tilly, Eric M. Burke | |||||||||||||||||||||
| You would expect there to have been an ant on the cover, but that creature was already spoken for Oracle PL /SQL Programming. Not one of O’Reilly’s better efforts. Does not properly cover Ant 1.5/1.7. | ||||||||||||||||||||||
| ||||||||||||||||||||||
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.17] | The information on this page is for non-military use only. | ||
| You are visitor number 34,191. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/Mindprod website mirror) | ||
| http://mindprod.com/jgloss/ant.html | J:\mindprod\jgloss\ant.html | ||