maven resource解释

maven resource解释


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:

  1. <project xmlns=""
  2. xmlns:xsi=""
  3. xsi:schemaLocation="
  5. <build>
  6. ...
  7. <resources>
  8. <resource>
  9. <targetPath>META-INF/plexus</targetPath>
  10. <filtering>false</filtering>
  11. <directory>${basedir}/src/main/plexus</directory>
  12. <includes>
  13. <include>configuration.xml</include>
  14. </includes>
  15. <excludes>
  16. <exclude>**/*.properties</exclude>
  17. </excludes>
  18. </resource>
  19. </resources>
  20. <testResources>
  21. ...
  22. </testResources>
  23. ...
  24. </build>
  25. </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 or false, 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 between include and exclude, exclude wins.
  • testResources: The testResources element block contains testResource elements. Their definitions are similar to resource 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.