Maven - Resources

Card Puncher Data Processing

Maven - Resources

About

Maven supports two kinds of resources.

Type

Application

application resources or resources that the application needs

  • Default location: basedir/src/main/resources

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.

Configuration

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.

Management

Filtering

Maven Properties can be included in resources.

See https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

Share between modules

See http://maven.apache.org/plugins/maven-remote-resources-plugin/

Documentation / Reference





Discover More
Card Puncher Data Processing
Maven - Bin (Bash and Bat file creation)

How to create standard bash and/or dos file to start a Java application. With resource filtering, you can create a bash/dos script template. The steps are: defining the property value that will...
Card Puncher Data Processing
Maven - Build

A Build is just a run of maven. ... See build-helper-maven-plugin Example: Make sure every sub-project has LICENSE, NOTICE and...
Idea Maven Module
Maven - Module

module management in Maven. A multi-module project is defined by a parent POM referencing one or more sub-modules. The mechanism in Maven that handles multi-module projects is referred to as the reactor....
Card Puncher Data Processing
Maven - Repository

in Maven. A repository is a storage of artifacts (jar, war, zip ...) in a file system that is: local: or remote repository (ie via HTTP or SSH) Repository Client translate artifact coordinates...
Card Puncher Data Processing
Maven - process-resources

process-resources is a phase that copies and filters resources.



Share this page:
Follow us:
Task Runner