在pom.xml中,可以使用maven-resources-plugin插件来将资源文件加入到编译目录中。

  1. 标签下添加以下代码:
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
      <execution>
        <id>copy-resources</id>
        <phase>validate</phase>
        <goals>
          <goal>copy-resources</goal>
        </goals>
        <configuration>
          <outputDirectory>${project.build.directory}/classes</outputDirectory>
          <resources>
            <resource>
              <directory>src/main/resources</directory>
              <filtering>true</filtering>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>
  1. 标签下添加需要加入编译目录的资源文件路径。
<resources>
  <resource>
    <directory>src/main/resources</directory>
    <includes>
      <include>**/*.xml</include>
      <include>**/*.properties</include>
    </includes>
    <filtering>true</filtering>
  </resource>
</resources>

其中,指定资源文件的路径,指定需要加入编译目录的文件类型,表示是否对资源文件进行过滤

pom中如何把resource加入到编译目录

原文地址: https://www.cveoy.top/t/topic/dq1L 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录