maven tutorial: maven-resources-plugin plug-in usage example (organizing resource file directory)

In Maven, you can use maven-resources-pluginplug-ins to separate the resource files in the src/main/resources directory and generate an independent resource file package.

To use maven-resources-pluginthe plugin, you first need to add the following configuration to your project's pom.xml file:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-resources-plugin</artifactId>
      <version>3.2.0</version>
      <executions>
        <execution>
          <id>copy-resources</id>
          <phase>package</phase>
          <goals>
            <goal>copy-resources</goal>
          </goals>
          <configuration>
            <outputDirectory>${project.build.directory}/resources</outputDirectory>
            <resources>
              <resource>
                <directory>src/main/resources</directory>
                <includes>
                  <include>**/*</include>
                </includes>
              </resource>
            </resources>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

packageThe above configuration will execute the goal in the Maven phase copy-resourcesand copy all files in the src/main/resources directory to ${project.build.directory}/resourcesthe directory.

After executing mvn packagethe command, an independent resource file package will be generated, which contains all files in the src/main/resources directory. ${project.build.directory}/resourcesThis resource file package can be found in the directory.

Please note that this is just a method of separating resource files separately, and may need to be adjusted according to specific needs in actual applications.

Guess you like

Origin blog.csdn.net/a772304419/article/details/133358250