Apache Maven Standard Directory Layout

In this quick article, we’ll explore the standard directory layout of a typical Maven project. Having a common directory layout would allow for users familiar with one Maven project to immediately feel at home in another Maven project. The advantages are analogous to adopting a site-wide look-and-feel.
The next section documents the directory layout expected by Maven and the directory layout created by Maven. Please try to conform to this structure as much as possible; however, if you can't these settings can be overridden via the project descriptor.

Standard Directory Layout

A typical Maven project has a pom.xml file and a directory structure based on defined conventions:
└───maven-project
    ├───pom.xml
    ├───README.txt
    ├───NOTICE.txt
    ├───LICENSE.txt
    └───src
        ├───main
        │   ├───java
        │   ├───resources
        │   ├───filters
        │   └───webapp
        ├───test
        │   ├───java
        │   ├───resources
        │   └───filters
        ├───it
        ├───site
        └───assembly

The Root Directory

This directory serves as the root of every Maven project.
Let’s take a closer look at the standard files and subdirectories that are typically found at root:
  • maven-project/pom.xml – defines dependencies and modules needed during the build lifecycle of a Maven project
  • maven-project/LICENSE.txt – licensing information of the project
  • maven-project/README.txt – summary of the project
  • maven-project/NOTICE.txt – information about third-party libraries used in the project
  • maven-project/src/main – contains source code and resources that become part of the artifact
  • maven-project/src/test – holds all the test code and resources
  • maven-project/src/it – usually reserved for integration tests used by the Maven Failsafe Plugin
  • maven-project/src/site – site documentation created using the Maven Site Plugin
  • maven-project/src/assembly – assembly configuration for packaging binaries

The src/main Directory

As the name indicates, src/main is the most important directory of a Maven project. Anything that is supposed to be part of an artifact, be it a jar or war, should be present here.
Its subdirectories are:
  • src/main/java – Java source code for the artifact
  • src/main/resources – configuration files and others such as i18n files, per-environment configuration files, and XML configurations
  • src/main/webapp – for web applications, contains resources like JavaScript, CSS, HTML files, view templates, and images
  • src/main/filters – contains files that inject values into configuration properties in the resources folder during the build phase

The src/test Directory

The directory src/test is the place where tests of each component in the application reside.
Note that none of these directories or files will become part of the artifact. Let’s see its subdirectories:
  • src/test/java – Java source code for tests 
  • src/test/resources – configuration files and others used by configuration properties in the resources folder during the test phase

Summary

src/main/javaApplication/Library sources
src/main/resourcesApplication/Library resources
src/main/filtersResource filter files
src/main/webappWeb application sources
src/test/javaTest sources
src/test/resourcesTest resources
src/test/filtersTest resource filter files
src/itIntegration Tests (primarily for plugins)
src/assemblyAssembly descriptors
src/siteSite
LICENSE.txtProject's license
NOTICE.txtNotices and attributions required by libraries that the project depends on
README.txtProject's readme

Conclusion

In this article, we looked at the standard directory layout for an Apache Maven project. In the next article, we will learn how to create a simple maven project and learn different maven elements.
Multiple examples of Maven project structures can be found in the GitHub project.

Free Spring Boot Tutorial | Full In-depth Course | Learn Spring Boot in 10 Hours


Watch this course on YouTube at Spring Boot Tutorial | Fee 10 Hours Full Course

Comments