Apache Maven 1.x has reached its end of life, and is no longer supported. For more information, see the announcement. Users are encouraged to migrate to the current version of Apache Maven.

Building JARs

Building a JAR with Maven is one of the simplest uses, and it is the default project that Maven will build.

For a basic build example, you can see the Getting Started Guide. This goes through the steps of setting up a simple Java project and building a JAR.

What will happen is that the Java code will be compiled (as specified by the source directory you've given), resources copied into the root location for the JAR (also given in the project descriptor), the tests run, and a JAR bundled up.

To add additional files, such as a manifest - you can add more resources, and they will be copied into the root of the JAR with directories intact.

If you would like to customise the existing manifest, there are several properties that can be set. For example, maven.jar.mainclass=com.mycompany.Main will set the Main-Class attribute.

Everything you do with Java in Maven will build from this foundation. The following sections will describe resources, tests, and other functionality that is available to build files other than JARs.

For more information on the specifics of the JAR, please consult the JAR plugin documentation. Goals in Maven will have their documentation listed under their respective plugins in that documentation reference.

To continue to the next topic, see Working with Resources.