maven resource解释
Resources
Another feature of build
elements is specifying where resources exist within your project. Resources are not (usually) code. They are not compiled, but are items meant to be bundled within your project or used for various other reasons, such as code generation.
For example, a Plexus project requires a configuration.xml
file (which specifies component configurations to the container) to live within the META-INF/plexus
directory. Although we could just as easily place this file within src/main/resources/META-INF/plexus
, we want instead to give Plexus its own directory of src/main/plexus
. In order for the JAR plugin to bundle the resource correctly, you would specify resources similar to the following:
- <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
- https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <build>
- ...
- <resources>
- <resource>
- <targetPath>META-INF/plexus</targetPath>
- <filtering>false</filtering>
- <directory>${basedir}/src/main/plexus</directory>
- <includes>
- <include>configuration.xml</include>
- </includes>
- <excludes>
- <exclude>**/*.properties</exclude>
- </excludes>
- </resource>
- </resources>
- <testResources>
- ...
- </testResources>
- ...
- </build>
- </project>
- resources: is a list of resource elements that each describe what and where to include files associated with this project.
- targetPath: Specifies the directory structure to place the set of resources from a build. Target path defaults to the base directory. A commonly specified target path for resources that will be packaged in a JAR is META-INF.
- filtering: is
true
orfalse
, denoting if filtering is to be enabled for this resource. Note, that filter*.properties
files do not have to be defined for filtering to occur – resources can also use properties that are by default defined in the POM (such as ${project.version}), passed into the command line using the “-D” flag (for example, “-Dname
=value
“) or are explicitly defined by the properties element. Filter files were covered above. - directory: This element’s value defines where the resources are to be found. The default directory for a build is
${basedir}/src/main/resources
. - includes: A set of files patterns which specify the files to include as resources under that specified directory, using * as a wildcard.
- excludes: The same structure as
includes
, but specifies which files to ignore. In conflicts betweeninclude
andexclude
,exclude
wins. - testResources: The
testResources
element block containstestResource
elements. Their definitions are similar toresource
elements, but are naturally used during test phases. The one difference is that the default (Super POM defined) test resource directory for a project is${basedir}/src/test/resources
. Test resources are not deployed.