Maven:我可以在WEB-INF和其他目录中复制资源吗?

时间:2012-09-14 14:07:19

标签: maven

我想在2个不同的目录中复制一些资源。我如何在pom中指定它?

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.6</version>
  <executions>
    <execution>
      <id>copy-resources</id>
      <!-- here the phase you need -->
      <phase>validate</phase>
      <goals>
        <goal>copy-resources</goal>
      </goals>
      <configuration>
        <outputDirectory>
          ${project.build.directory}/${project.build.finalName}/lib
        </outputDirectory>
        <resources>          
          <resource>
            <directory>${SOME_LIB}</directory>
          </resource>
        </resources>              
      </configuration>                      
    </execution>
  </executions>
</plugin>

2 个答案:

答案 0 :(得分:1)

我会使用<resources/>块中的<build/>标记代替。

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <targetPath>${project.build.directory}/txt</targetPath>
            <includes>
                <include>*.txt</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <targetPath>${project.build.directory}/png</targetPath>
            <includes>
                <include>*.png</include>
            </includes>
        </resource>
        <resource>
            <directory>${SOME_LIB}</directory>
            <targetPath>${project.build.directory}/lib</targetPath>
            <includes>
                <include>*.dll</include>
            </includes>
        </resource>
    </resources>
</build>

这样您就可以将不同的文件分类到不同的目标路径。


对于您确切的问题,这可行:

<build>
    <resources>
        <resource>
            <directory>${SOME_LIB}</directory>
            <targetPath>${project.build.directory}/${project.build.finalName}/lib</targetPath>
        </resource>
        <resource>
            <directory>${SOME_LIB}</directory>
            <targetPath>${project.build.directory}/${project.build.finalName}/WEB-INF</targetPath>
    </resources>
</build>

资源将被复制到BOTH目标目录,就像您想要的那样。

答案 1 :(得分:0)

outputDirectories是一个java.io.File类型,所以根据插件,你必须配置2次执行。

可惜它不是为处理

而设计的
<outputDirectories>
    <outputDirectory>1</outputDirectory>
    <outputDirectory>2</outputDirectory>
</outputDirectories>