Building a Project with Maven

The vast majority of Maven-built projects can be built with the following command:

mvn clean install

This command tells Maven to build all the modules, and to install it in the local repository. The local repository is created in your home directory (or alternative location that you created it), and is the location that all downloaded binaries and the projects you built are stored.

That's it! If you look in the target subdirectory, you should find the build output and the final library or application that was being built.

Note: Some projects have multiple modules, so the library or application you are looking for may be in a module subdirectory.

While this will build most projects and Maven encourages this standard convention, builds can be customisable. If this does not suffice, please consult the project's documentation.

More than just the Build

Maven can do more than just build software - it can assist with testing, run web applications and produce reports on projects, as well as any number of other tasks provided by plug-ins.

When Things go Wrong

The following are some common problems when building with Maven, and how to resolve them.

Missing Dependencies

A missing dependency presents with an error like the following:

[INFO] Failed to resolve artifact.

1) jnuit:junit:jar:3.8.1

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=jnuit -DartifactId=junit \
          -Dversion=3.8.1 -Dpackaging=jar -Dfile=/path/to/file

  Path to dependency:
        1) org.apache.maven:maven:pom:2.1-SNAPSHOT
        2) jnuit:junit:jar:3.8.1

1 required artifact is missing.

for artifact:

from the specified remote repositories:
  central (

To resolve this issue, it depends on what the dependency is and why it is missing. The most common cause is because it can not be redistributed from the repository and must be manually installed using the instructions given in the message. This is most common with some older JARs from Sun (usually javax.* group IDs), and is further documented in the Guide to Coping with Sun JARs.

You can check the list of repositories at the end of the error to ensure that the expected ones are listed - it may be that the project requires an alternative repository that has not been declared properly or is not accessible with your Maven configuration.

In other cases, it may be an incorrectly declared dependency (like the typo in the example above) which the project would need to fix, like a compilation error.