很容易使用org.apache.maven.plugins:maven-antrun-plugin
复制资源并重命名它们,但有没有一种方法可以使用通配符或其他机制来智能地执行此操作以符合个人规则?
例如,如果我有这些文件:
${project.artifactId}-${project.version}.swf
a.swf
b.swf
- ...
z.swf
我想复制目录中的所有这些文件并仅重命名${project.artifactId}-${project.version}.swf
to foo.swf
。我知道我可以使用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>copy-swf-files</id>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="copy swf files to web project">
<copy file="${project.build.directory}/${project.artifactId}-${project.version}.swf" tofile="${swf.output.location}/foo.swf" />
<copy file="${project.build.directory}/a.swf" tofile="${swf.output.location}/a.swf" />
<copy file="${project.build.directory}/z.swf" tofile="${swf.output.location}/z.swf" />
</target>
</configuration>
</execution>
</executions>
</plugin>
这是可行的,但是有另一种方便的方法可以做到这一点,因为如果我有 1000 个文件要复制,那会很无聊......谢谢
你知道蚂蚁吗? Maven Ant 插件所做的所有事情就是使用您列出的任务调用 Ant。您可以执行任何 Ant 任务,包括<taskdef>
, etc.
您正在做的事情可以通过文件集来完成:
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}">
<include name="*.swf"/>
</fileset>
</copy>
这将复制所有*.swf
文件直接位于${project.build.directory}
(并且没有子目录)到${swf.output.location}
目录。如果你想复制整个目录树*.swf
文件,只需更改<include>
:
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}">
<include name="**/*.swf"/> <!--NOTE DIFFERENCE HERE-->
</fileset>
</copy>
如果您需要修改文件名,可以使用Mappers。最简单的映射器是展平映射器:
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}">
<include name="**/*.swf"/> <!--NOTE DIFFERENCE HERE-->
</fileset>
<mapper type="flatten"/>
</copy>
这将复制整个目录树并将所有文件合并到一个目录中。有些映射器可以匹配全局变量、正则表达式,甚至脚本。
The <include>
is a selector而不是映射器,因为它选择您想要操作的文件。这些也可能非常复杂,您可以根据文件的名称和正则表达式甚至其内容来匹配文件。
我很惊讶没有 Maven 插件可以让你做到这一点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)