Questions tagged [ant]

Apache Ant (formerly Jakarta Ant) is a declarative, XML-based build tool created originally for Java projects. It provides a rich set of standard tasks for performing most common build operations, such as compiling Java source, building archives and running tests. Ant's functionality can be extended through custom tasks and macros.

Ant

Apache Ant is a Java open-source library and command-line tool whose mission is to drive processes described in XML build files as targets and extension points dependent upon each other. Most commonly, Ant is used to build Java applications.

It supplies a number of built-in tasks allowing to compile, assemble, test and run applications. Although primarily aimed at building Java applications, Ant can also be used effectively to build non-Java software, for instance C or C++ applications.

More generally, Ant can be used to pilot any type of process which can be described in terms of targets, tasks, and macros. It's a standard and effective framework which transforms a development structure of project to a deployment structure.

Ant was historically meant as a replacement and Java counterpart for the Unix Make build utility.

References

Extensions

Example

Hello, World!

A build.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorld" default="world" basedir=".">
  <target name="world" depends="message" description="outputs a friendly message">
    <echo message="World!" />
  </target>
  <target name="message">
    <echo message="Hello, " />
  </target>
</project>

This project can be run from the directory containing the build.xml file by just typing:

  • ant
  • or ant -f build.xml

The list of available self-documenting targets can be viewed with ant -p.

15413 questions
60
votes
1 answer

How to Pass parameters for a Ant script , which is invoked via shell script?

I need to invoke a ant script via shell script. Let us consider the parameters for ant script are a,b,c. how can i pass the parameter for those variables? I must provide the parameters for ant vis invoke the shell script. can anyone help me on this?
trilawney
  • 1,786
  • 6
  • 28
  • 36
60
votes
4 answers

How do I make ANT verbose?

Trying to build my project with ANT in idea 10 and I get a compile error but I don't see the actual error. How do I make ANT verbose? All I see is: javac build.xml:303: Compile failed; see the compiler error output for details.…
sproketboy
  • 8,967
  • 18
  • 65
  • 95
59
votes
5 answers

Use Ant for running program with command line arguments

My program getting command line arguments. How can I pass it when I use Ant?
Victoria Seniuk
  • 1,384
  • 3
  • 14
  • 23
59
votes
10 answers

Java project: should .classpath .project file be committed into repository?

Should I check in my .project and .classpath files? My friend told me that I should only check in .java files and the build.xml to guarantee portability. He said ".classpath will cause you much less portability on different environment. .project is…
sean
  • 817
  • 2
  • 9
  • 7
59
votes
7 answers

How to lookup the latest git commit hash from an ant build script

How can I lookup the latest git commit hash from an ant build script? I am currently working on a new open source project which I store on github. I would like to extend my existing ANT build file to allow me to create numbered builds. I am…
mchr
  • 6,161
  • 6
  • 52
  • 74
56
votes
3 answers

define ant property from environment with default value

I would like my build script to act properly for release and development environments. For this I would like to define a property in ant, call it (e.g.) fileTargetName fileTargetName will get it's value from the environment variable RELEASE_VER if…
Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
56
votes
1 answer

Maven or Ivy? Which one is better with a system already in production? And the other differences?

I know that this is a complicated question, but I would like know which one is better in the case of a system that it's already in production, with a lot of bugs and really bad design at all. A really mess. Actually, I'm asking this because I'm…
Pmt
  • 1,122
  • 3
  • 13
  • 27
55
votes
4 answers

Why am I getting a ClassCastException when generating javadocs?

I'm using ant to generate javadocs, but get this exception over and over - why? I'm using JDK version 1.6.0_06. [javadoc] java.lang.ClassCastException: com.sun.tools.javadoc.ClassDocImpl cannot be cast to com.sun.javadoc.AnnotationTypeDoc …
ScArcher2
  • 85,501
  • 44
  • 121
  • 160
54
votes
3 answers

Ant to Maven - multiple build targets

I have an Ant build that is currently being converted to Maven. However, the Ant build has 2 build targets - one that builds the entire app, and one that builds a JAR from some of those files (only a few). In Ant, it's easy to have multiple build…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
53
votes
11 answers

This compilation unit is not on the build path of a Java project

When I try to use ctrl+space this error is shown: This compilation unit is not on the build path of a Java project. I see that there are similar topics but my work environment is Eclipse and i pull my project from Git (I import project as general…
52
votes
10 answers

ant build.xml file doesn't exist

After the installation of my ant in my windows 7 . In cmd i typed ant -v it's given the ant version but it says the following also. Buildfile: build.xml does not exist! Build failed What's the problem in the system. How i can rectify this issue?
Miko
  • 2,615
  • 9
  • 33
  • 58
51
votes
5 answers

ant depends vs. antcall

When defining sequential build steps I use the depends attribute of the target element. I have recently seen an ant file, where the build sequence was defined by antcall elements inside the targets. To illustrate :
kostja
  • 60,521
  • 48
  • 179
  • 224
51
votes
17 answers

"Forked Java VM exited abnormally" error from junit tests

I have a java junit test that passes when run alone on a development machine. We also have a hudson job which runs all the tests, invoked via ant, on a Mac OS X 10.4 node with Java 1.5. The test was passing in the hudson build until recently but now…
Alb
  • 3,601
  • 6
  • 33
  • 38
51
votes
6 answers

how to detect a build error from ant/maven via a bash script?

I am writing a bash script to automate the build process. There are two major build blocks, one is an ant task and one is a plain old mvn clean install. I want to do something when there is build error coming from either of this two build processes.…
fei
  • 2,224
  • 9
  • 31
  • 36
51
votes
6 answers

How do I add time-stamp information to Maven artifacts?

I am upgrading a large build-system to use Maven2 instead of Ant, and we have two related requirements that I'm stuck on: We need to generate a time-stamped artifact, so a part of the package phase (or wherever), instead of building…
Ryan
  • 525
  • 1
  • 4
  • 6