它很容易用于org.apache.maven.plugins:maven-antrun-plugin复制资源并重命名它们,但有没有办法通过通配符或其他机制智能地执行此操作以符合个人规则?
例如,如果我有这些文件:
${project.artifactId}-${project.version}.swfa.swfb.swfz.swf我想复制目录中的所有文件并仅重命名${project.artifactId}-${project.version}.swf为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>
Run Code Online (Sandbox Code Playgroud)
它的工作,但有另一种方便的方法,因为如果我有1000个文件要复制,这将是非常无聊的...谢谢
Dav*_* W. 16
你知道蚂蚁吗?所有Maven Ant插件正在使用您列出的任务调用Ant.你可以做任何Ant任务,包括<taskdef>等等.
您正在做的事情可以通过文件集完成:
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}">
<include name="*.swf"/>
</fileset>
</copy>
Run Code Online (Sandbox Code Playgroud)
这会将*.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>
Run Code Online (Sandbox Code Playgroud)
如果需要使用文件名,可以使用Mappers.最简单的映射器将是展平映射器:
<copy todir="${swf.output.location}">
<fileset dir="${project.build.directory}">
<include name="**/*.swf"/> <!--NOTE DIFFERENCE HERE-->
</fileset>
<mapper type="flatten"/>
</copy>
Run Code Online (Sandbox Code Playgroud)
这将复制整个目录树并将所有文件压缩到一个目录中.有映射器可以匹配globs,正则表达式,甚至脚本.
它<include>是一个选择器而不是映射器,因为它选择了您想要操作的文件.这些也可能非常复杂,您可以根据文件的名称匹配文件iva正则表达式,甚至是内容.
我很惊讶没有Maven插件允许你这样做.
使用带有“dir”“formats/format”程序集描述符的 maven- assembly-plugin,一个“fileSets/fileSet”将复制除特殊 swf 之外的大多数 swf,以及一个“files/file”将把该 swf 复制到具有不同名称的文件。
| 归档时间: |
|
| 查看次数: |
38025 次 |
| 最近记录: |