Maven:如何以不同的结构复制子文件夹及其内容 [英] Maven: How to copy sub folders and their content in a different structure
问题描述
在Maven项目中,我有目录,我需要其中的内容.
In a Maven project, I have directory, which I need the content from..
${basedir}/target/webapp-SNAPSHOT/WEB-INF/vendorspace/
|- dealo
|-static
|- css
|- images
|- js
|- blog
|- static
|-css
|-images
|-js
------
我想将静态目录的内容复制为
And I want to copy the content of static directory to its parent directory as
${basedir}/target/tstatic/
|- dealo
|- css
|- images
|- js
|- blog
|-css
|-images
|-js
一种解决方案是给文件夹命名,如下所示:
One solution is to give name of the folder like this:
<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个文件夹,并且将来还会增加,所以不想提供硬编码的名称
but I have 10's of those folders and it will grow in future so don't want to give hard-coded name
相关问题: Maven:复制没有子目录结构的文件 但它只复制文件,我需要复制静态"目录中的子目录及其内容
Related question: Maven : copy files without subdirectory structure but it is copying only files, I need to copy the sub-directories inside "static" directory with its content
推荐答案
I would suggest to use the maven-war-plugin to handle such things like the following:
<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>
还可以通过配置关闭过滤等:
It's also possible to turn off filtering etc. via configuration:
<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>
这篇关于Maven:如何以不同的结构复制子文件夹及其内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!