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.
Here are the most important directories:
Directory | Stores |
---|---|
src/main/java | Application/Library sources |
src/main/resources | Application/Library resources |
src/main/config | Configuration files |
src/main/scripts | Application/Library scripts |
src/main/webapp | Web application sources |
src/test/java | Test sources |
src/test/resources | Test resources |
src/assembly | Assembly descriptors |
src/site | Site |
target | The target directory is used to store all output of the build. |
LICENSE.txt | Project's license |
NOTICE.txt | Notices and attributions |
README.txt | Project'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.