Chapter 19

Developing with Build Tools

There is much more to creating a usable application than writing Java source code. Applications comprise many different artifacts, XML configuration, and environment-specific properties, and even images or embedded code for other languages.

This chapter looks at two applications that focus on pulling all your project’s resources together into a coherent bundle. Maven and Ant are possibly the two most-used and best-understood build tools for Java projects.

Any non-trivial professional application will need something other than the Java compiler to create distributable applications—sometimes you can use a simple shell script—but the chances are that something will be Maven or Ant.

Building Applications with Maven

What is Maven?

Maven is an all-encompassing build tool. It is used to compile, test, and deploy Java projects.

It has been designed to favor convention over configuration. For the most part, builds for Java applications can be defined in a very similar manner, and if you define the layout of your source code in the same way, Maven knows where to find all the resources it needs and can perform many different build tasks.

Maven has built-in defaults for most settings, so whether your application will be deployed as a Web Archive (WAR) file or as a JAR file, Maven has defined tasks for how to build these properly.

A non-trivial Java application will have dependencies on many other libraries, such as unit-testing frameworks like JUnit ...

Get Java Programming Interviews Exposed now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.