Maven - Resources

> Maven

1 - About

Maven supports two kinds of resources.

Advertising

3 - Type

3..1 - Application

application resources or resources that the application needs

  • Default location: ${basedir}/src/main/resources

3..2 - Test

Test resources used during the test phase and that is not deployed

  • Default location: ${basedir}/src/test/resources
  • During the test, they are automatically copied over to /target/test-classes.

4 - Configuration

4.1 - Pom

Maven - pom.xml - Project Object Model. See https://maven.apache.org/pom.html#Resources

<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>
    ...
    <! -- a list of resource elements that each describe what and where to include files associated with this project -->
    <resources>
      <resource>
        <!-- Source Directory (Default: ${basedir}/src/main/resources) -->
        <directory>${basedir}/src/main/plexus</directory>
        <!-- Target path in the build: 
                default value: base directory
                for a Jar: a common value is META-INF.
        -->
        <targetPath>META-INF/plexus</targetPath>
        <!-- TRUE or FALSE -->
        <filtering>false</filtering>
        <!-- A set of include files patterns using * as a wildcard. -->
        <includes>
          <include>configuration.xml</include>
        </includes>
        <!-- A set of exclude files patterns using * as a wildcard. 
        Between include and exclude, exclude wins always -->
        <excludes>
          <exclude>**/*.properties</exclude>
        </excludes>
      </resource>
    </resources>
 
 
    <!-- test phases resources used during the test phase and that is not deployed -->
    <testResources>
      <resource>
        <!-- Source Directory (Default: ${basedir}/src/test/resources) -->
        <directory>${basedir}/src/test/plexus</directory>
      </resource>
    </testResources>
  </build>
</project>

The pom Xml Resources can also use properties.

5 - Management

5.1 - Filtering

Advertising

5.2 - Share between modules

6 - Documentation / Reference