There are times when you will want to build using Apache Ant. Maybe your project is using an automated process which relies on Ant, or maybe you have some team members who are not yet comfortable making the transition to Maven and who wish to continue using Ant. Since many IDEs already support projects with Ant build files, you can use Maven to generate a build.xml file so that your project can be built using Apache Ant.
Run the Ant plug-in. Running maven
ant
will create a build.xml file which contains targets to
gather dependencies, build, and test your application. Take a look at
the output of running the default jar
target:
C:\dev\mavenbook\code\genapp\test-application>ant
Buildfile: build.xml
init:
[mkdir] Created dir: C:\dev\mavenbook\code\genapp\target\lib
get-deps:
[get] Getting: http://www.ibiblio.org/maven/springframework/jars/spring-core-1.1.4.jar
[get] Getting: http://www.ibiblio.org/maven/springframework/jars/spring-web-1.1.4.jar
compile:
[copy] Copying 1 file to C:\dev\mavenbook\code\genapp\target\classes
junit-present:
[echo] = = = = = = = = = = = = = = = = = = WARNING = = = = =
= = = = = = = = = = = = = = = = = = =
[echo] Junit isn't present in your ${ANT_HOME}/lib directory. Tests not executed.
[echo] = = = = = = = = = = = = = = = = = = = = = = = = =
= = = = = = = = = = = = = = = = = = = = = = =
compile-tests:
internal-test:
test:
jar:
[jar] Building jar: C:\dev\mavenbook\code\genapp\test-application\target\
test-application-1.0.jar
BUILD SUCCESSFUL
Total time: 2 seconds
You may have noticed that there is a problem, and it is an
illustrative problem. Apache Ant does not automatically manage the
dependencies for optional Ant tasks. If you want to run the JUnit
tests, you will need to copy the junit-3.8.1.jar file from the local Maven
repository to ${ANT_HOME}/lib.
This build file contains a get-deps
target which executes the Ant get
task to grab all of the project's dependencies from the remote Maven
repository at http://www.ibiblio.org/maven.
...trying to get away from Ant? Isn't Maven a replacement for Ant?
Yes and no. Ant isn't "bad," and the majority of tools still work with
Ant. There is no reason not to provide interoperability with Apache
Ant, and once you learn more about Jelly in Section 2.1, you'll see that
Ant tasks are used extensively in Maven. Many projects use a
continuous integration system which may expect an Ant build file.
Running maven ant
provides an easy
way to continue to support these tools.
Note
Although this is changing rapidly; many tools such as AntHill and Gump are starting to support both Ant and Maven. But, if you are still working with a tool that expects an Ant build file, run maven ant.
Get Maven: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.