2

在 Maven 项目中,我有目录,我需要来自..的内容

${basedir}/target/webapp-SNAPSHOT/WEB-INF/vendorspace/  
    |- dealo  
         |-static  
             |- css  
             |- images  
             |- js  
    |- blog  
         |- static
             |-css
             |-images
             |-js
    ------

我想将静态目录的内容复制到其父目录

${basedir}/target/tstatic/
     |- dealo  
          |- css  
          |- images  
          |- js  
     |- blog  
          |-css
          |-images
          |-js  

一种解决方案是像这样给出文件夹的名称:

 <copy todir="${basedir}/target/vstatic/dealo">
   <fileset dir="${basedir}/target/webapp-SNAPSHOT/WEB-INF/vendorspace/dealo/static/" includes="**/*" />  
 </copy>  
 <copy todir="${basedir}/target/vstatic/blog">
   <fileset dir="${basedir}/target/webapp-SNAPSHOT/WEB-INF/vendorspace/blog/static/" includes="**/*" />
 </copy>

但我有 10 个这样的文件夹,将来会增长,所以不想给出硬编码的名称

相关问题:Maven:复制没有子目录结构 的文件,但它只复制文件,我需要复制“静态”目录中的子目录及其内容

4

1 回答 1

4

我建议使用maven-war-plugin来处理类似以下的事情:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <webResources>
            <resource>
              <!-- this is relative to the pom.xml directory -->
              <directory>resource2</directory>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
  ...
</project>

也可以通过配置关闭过滤等:

  <configuration>
      <!-- the default value is the filter list under build -->
      <!-- specifying a filter will override the filter list under build -->
      <filters>
        <filter>properties/config.prop</filter>
      </filters>
      <nonFilteredFileExtensions>
        <!-- default value contains jpg,jpeg,gif,bmp,png -->
        <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
      </nonFilteredFileExtensions>
      <webResources>
        <resource>
          <directory>resource2</directory>
          <!-- it's not a good idea to filter binary files -->
          <filtering>false</filtering>
        </resource>
        <resource>
          <directory>configurations</directory>
          <!-- enable filtering -->
          <filtering>true</filtering>
          <excludes>
            <exclude>**/properties</exclude>
          </excludes>
        </resource>
      </webResources>
    </configuration>
于 2013-04-30T09:33:58.133 回答