Matthias
Matthias

Reputation: 3556

maven pom's resource element

i am new to maven and came across the resources section. The reference for the maven project descriptor (version 4.0) states that "this element describes all of the classpath resources associated with a project or unit tests" (link). However this description i do not understand/seems to abstract for me. Why would i want to describe classpath resources? How does it affect the projects lifecycle?

matthias

Upvotes: 6

Views: 20676

Answers (2)

weekens
weekens

Reputation: 8282

This feature allows you, for example, to use Maven variables inside your .properties files. Just declare the directory, where your .properties are, in <resources> section, and you'll be able to use ${project.name} or whatever.

pom.xml:

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

version.properties:

version=${pom.version}
timestamp=${timestamp}

(${timestamp} is created with Maven Build Number plugin).

Upvotes: 1

khmarbaise
khmarbaise

Reputation: 97359

usually you have the src/main/resources folder which contains resources which will be packaged into a jar. This everything which is in the above folder will automatically be packaged into a jar and is accessible via getResource... Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder.

<project>
  ...
  <name>My Resources Plugin Practice Project</name>
  ...
  <build>
    ...
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      ...
    </resources>
    ...
  </build>
  ...
</project>

The lifecycle of Maven is not influenced by this.

Upvotes: 11

Related Questions