Table of Contents

About

Maven relies on the Standard Directory Layout

Standard project structure

A standard project

${basedir}
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |   |   `-- com
    |   |       `-- mycompany
    |   |           `-- app
    |   |               `-- App.java
    |   `-- sql, groovy, ...
    |   `-- resources
    |       `-- META-INF
    |           `-- application.properties
    |-- test
    |   `-- java
    |   |   `-- com
    |   |       `-- mycompany
    |   |           `-- app
    |   |               `-- AppTest.java
    |   `-- resources
    |       `-- test.properties
    `-- target
        `-- classes
            `-- com
                `-- mycompany
                      `-- app
                        `-- App.class

where:

  • the src/main/java directory contains the project source code,
  • the src/main/resources directory contains the project resources,
  • the src/test/java directory contains the test source,
  • the src/test/resources directory contains the test resources,
  • the target/classes directory contains the compiled classes
  • the pom.xml file is the project's Project Object Model, or POM.

basedir represents the directory containing pom.xml

Configuration

Build pom.xml elements

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <build>
    <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
    <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
    <outputDirectory>${basedir}/target/classes</outputDirectory>
    <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
    <directory>${basedir}/target</directory>
    ...
  </build>
</project>

If the values of a *Directory element above is set as an absolute path (when their properties are expanded) then that directory is used. Otherwise, it is relative to the base build directory: basedir.

For resources, check the pom.xml reference and the following article Resources: Including and excluding files and directories

<build>
	...
	<resources>
	  <resource>
		<directory>src/my-resources</directory>
		<includes>
		  <include>**/*.txt</include>
		  <include>**/*.rtf</include>
		</includes>
	  </resource>
	  ...
	</resources>
	...
</build>

Documentation / Reference