Maven Tutorial - Maven Directory Structure

Having a common directory layout allows users to be familiar with Maven project from one to another.

Maven defines a standard directory structure.

- src
  - main
    - java
    - resources
    - webapp
  - test
    - java
    - resources

- target

The src directory is the root directory of source code and test code.

The main directory is the root directory for source code related to the application itself, not test code.

The test directory contains the test source code.

The java directories under main and test contains the Java code for the application itself which is under main and the Java code for the tests which is under test.

The resources directory contains the resources needed by your project.

The target directory is created by Maven. It contains all the compiled classes, JAR files etc.

When executing the mvn clean command, Maven would clean the target directory.

The webapp directory contains Java web application, if the project is a web application.

The webapp directory is the root directory of the web application. The webapp directory contains the WEB-INF directory.

If you follow the directory structure, you do not need to specify the directories of your source code, test code, resource files, etc. in your POM file.

Directory Structure

Here are the most important directories:

Directory Stores
src/main/javaApplication/Library sources
src/main/resourcesApplication/Library resources
src/main/configConfiguration files
src/main/scriptsApplication/Library scripts
src/main/webappWeb application sources
src/test/javaTest sources
src/test/resourcesTest resources
src/assemblyAssembly descriptors
targetThe target directory is used to store all output of the build.
LICENSE.txtProject's license
NOTICE.txtNotices and attributions
README.txtProject's readme

At the top of the project root there are pom.xml file and any properties, maven.xml.

In addition, there are text files for the user to read immediately on receiving the source: README.txt, LICENSE.txt, etc.

There are two subdirectories of this structure: src and target.

The src directory contains all of the source material for building the project, its site and so on.

It contains a subdirectory for each type: main for the main build artifact, test for the unit test code and resources, site and so on.

Within source directories, main and test, there is one directory for the language java, under which there are the normal package hierarchy, and one for resources.

The resources under is copied to the target classpath.

If there are other contributing sources to the artifact build, they would be under other subdirectories: for example src/main/antlr would contain Antlr grammar definition files.