Layout #
The standard directory layout #
By default, a Maven project is expected to comply with the so-called “standard directory layout”.
Warning. We restrict here the layout to files and folders that you are likely to use in your project. A comprehensive description can be found here.
├── pom.xml
├── README.md
├── src
│ ├── main
│ │ ├── java
│ │ │ └── ...
│ │ └── resources
│ │ └── ...
│ └── test
│ ├── java
│ │ └── ...
│ └── resources
│ └── ...
...
Here is the intended purpose of these files and directories (all paths are from the root of the project):
file or directory | content |
---|---|
pom.xml |
Maven configuration for the project |
README or README.md |
(human readable) description of the project |
src/main/java |
source code of the project |
src/main/resources |
resources for the project (e.g. additional configuration files, images, etc.) |
src/test/java |
source code for unit tests |
src/test/resources |
resources for unit tests (e.g. data) |
Note. By default, the content of the
src/main/resources
directory is automatically included in a jar generated with Maven.
Hint. Your IDE can generate this folder structure (together with a minimal
pom.xml
file).For instance, with IntelliJ, click on
File/New/Project
, and then select “Maven” as the “Build system”:
Hint. In some cases, a folder structure and
pom.xml
file that are tailored to a certain framework (like JavaFX or JSP) can be generated. This is called a maven archetype.
The target
directory
#
When building a Maven project, some files and directories are generated.
By default, the directory called target
(at the root of the project) contains the output of the build, in particular:
- the bytecode (i.e.
.class
files), - the generated
.jar
file(s), if any.
Hint. Since it is automatically generated, the
target
directory can be safely deleted.
Maven and Git #
The pom.xml
file should usually be committed.
However, the following should not be committed (i.e. should be ignored via .gitignore
):
- the
target
directory, - any other content generated during the build (e.g. generated source code, etc.).