Main difference between ANT and Maven



The main difference between ANT and Maven is that in ANT you need to define everything i.e. source directory, build directory, target directory etc while Maven adopts the principle of Convention over configuration.

Maven also provides dependency management, standard project layout, and project management. Maven has predefined project structure i.e. standard directory for source files, test files, and resources.

e.g. in Maven java source file in ${basedir}/src/main/java, resources on ${basedir}/src/main/resources, JUnit test cases on ${basedir}/src/test/java etc. It also creates Java class files on ${basedir}/target/classes and JAR file on ${basedir}/target directory. On the other hand, ANT requires all these directories supplied as configuration, usually in ANT build file e.g. build.xml.


Just to list some more differences:

  • Ant doesn’t have formal conventions. You have to tell Ant exactly where to find the source, where to put the outputs, etc.
  • Ant is procedural. You have to tell Ant exactly what to do; tell it to compile, copy, then compress, etc.
  • Ant doesn’t have a lifecycle.
  • Maven uses conventions. It knows where your source code is automatically, as long as you follow these conventions. You don’t need to tell Maven where it is.
  • Maven is declarative; All you have to do is create a pom.xml file and put your source in the default directory. Maven will take care of the rest.
  • Maven has a lifecycle. You simply call mvn install and a series of sequence steps are executed.
  • Maven has intelligence about common project tasks. To run tests, simple execute mvn test, as long as the files are in the default location. In Ant, you would first have to JUnit JAR file is, then create a classpath that includes the JUnit JAR, then tell Ant where it should look for test source code, write a goal that compiles the test source and then finally execute the unit tests with JUnit.