• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Maven | Maven Javadoc Plugin
  1. Maven Resources Plugin
  2. The help goal
  3. Example: Using resources plugin

  1. Maven Resources Plugin
    The Maven Resources Plugin handles the copying of project resources to the output directory.

    There are two different kinds of resources: main resources and test resources.

    The difference is that the main resources are the resources associated with the main source code while the test resources are associated with the test source code. This allows the separation of resources for the main source code and its unit tests.

    Plugin coordinates:
    • Group Id: org.apache.maven.plugins
    • Artifact Id: maven-resources-plugin
    • Version: 3.3.1

    Plugin Prefix: resources

    The resources plugin has the following goals:
    • help: Displays help information on the maven-resources-plugin.

    • resources: Copies resources for the main source code to the main output directory (src/main/resources/* → target/classes/).
      This goal is bound to the process-resources phase by default.
      It uses the project.build.resources element to specify the resources to copy.

    • testResources: Copies resources for the test source code to the test output directory (src/test/resources/* → target/test-classes/).
      This goal is bound to the process-test-resources phase by default.
      It uses the project.build.testResources element to specify the resources to copy.

    • copy-resources: Copies resources from a configured source directory to a specified output directory.
      This goal is not bound to any lifecycle phase by default and must be explicitly configured.

    Some configuration options:
    • encoding: Character encoding for reading and writing files (default: platform encoding).
    • filtering: Enable Maven property and filter substitution in resources.
    • includeEmptyDirs: Whether to include empty directories when copying.
    • overwrite: Whether to overwrite read-only destination files.
    • escapeWindowsPaths: Escape Windows paths in filtered resources.
  2. The help goal
    The help goal provides general information about the resources plugin, including available goals and their parameters.

    Use the detail parameter to get detailed information about all goals and their configuration options:
    # Display basic plugin information
    $ mvn resources:help
    
    # Display detailed information about all goals and parameters
    $ mvn resources:help -Ddetail=true
    If you need to use the plugin's full coordinates instead of its prefix, you can do that as follows:
    # Display basic plugin information
    $ mvn org.apache.maven.plugins:maven-resources-plugin:3.3.1:help
    
    # Display detailed information about all goals and parameters
    $ mvn org.apache.maven.plugins:maven-resources-plugin:3.3.1:help -Ddetail=true
    You can also use the Maven help plugin to describe the resources plugin:
    # Basic plugin description using help plugin
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-resources-plugin:3.3.1"
    
    # Detailed plugin description with all parameters
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-resources-plugin:3.3.1" -Ddetail=true
    To get specific information about a goal, use the goal parameter:
    # Help for the 'resources' goal
    $ mvn org.apache.maven.plugins:maven-resources-plugin:3.3.1:help -Dgoal=resources -Ddetail=true
    
    # Help for the 'resources' goal using the help plugin
    $ mvn help:describe -Dplugin="org.apache.maven.plugins:maven-resources-plugin:3.3.1" -Dgoal=resources -Ddetail=true
    Note: When using the plugin's help goal directly, you don't need to specify the version if the plugin is already configured in your POM or if you want to use the latest version.
  3. Example: Using resources plugin
    Configure your pom.xml file with the following plugin configuration:
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.3.1</version>
    
        <configuration>
            <!-- Set the character encoding for resources -->
            <encoding>UTF-8</encoding>
            <!-- Include empty directories when copying resources -->
            <includeEmptyDirs>false</includeEmptyDirs>
        </configuration>
    
        <executions>
            <!-- Copy test resources: src/test/resources/* → target/test-classes/ -->
            <execution>
                <id>default-testResources</id>
                <phase>process-test-resources</phase>
                <goals>
                    <goal>testResources</goal>
                </goals>
            </execution>
    
            <!-- Copy main resources: src/main/resources/* → target/classes/ -->
            <execution>
                <id>default-resources</id>
                <phase>process-resources</phase>
                <goals>
                    <goal>resources</goal>
                </goals>
            </execution>
    
            <!-- Custom resource copying example -->
            <execution>
                <id>copy-resources</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/bin-nix</outputDirectory>
                    <resources>
                        <resource>
                            <directory>${project.build.directory}/bin</directory>
                            <!-- Copy all files except Windows-specific ones -->
                            <excludes>
                                <exclude>win/**</exclude>
                            </excludes>
                            <!-- Enable resource filtering for variable substitution -->
                            <filtering>true</filtering>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
© 2025  mtitek