Maven和Ant的插件,能够智能地复制资源 [英] Maven and Ant plugin to copy resources intelligently

查看:220
本文介绍了Maven和Ant的插件,能够智能地复制资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很容易使用 org.apache.maven.plugins:Maven的antrun-插件复制资源,并重新命名,但有什么办法可以用通配符智能做到这一点或其他mecanisms符合的personnal规则?

It's easy to use org.apache.maven.plugins:maven-antrun-plugin to copy resources and rename them but is there a way to do this intelligently with wildcards or other mecanisms to conform personnal rules ?

例如,如果我有这些文件:

For example if I have those files :


  • $ {project.artifactId} - $ {} project.version的.swf

  • A.swf中

  • B.swf中

  • ...

  • z.swf

  • ${project.artifactId}-${project.version}.swf
  • a.swf
  • b.swf
  • ...
  • z.swf

我想所有这些文件复制内部目录,仅重命名 $ {project.artifactId} - $ {} project.version的.swf foo.swf 。我知道我可以使用:

I would like to copy all those files inside directory and rename only ${project.artifactId}-${project.version}.swf to foo.swf. I know I can use :

<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个文件进行复制,这将是很无聊...谢谢

it's work but is there another convenient way to do that because if I have 1000 files to copy, it will be very boring...Thanks

推荐答案

你知道蚂蚁?所有Maven的蚂蚁插件正在做的是调用Ant的与您列出的任务。你可以做任何Ant任务包括&LT;的taskdef方式&gt;

Do you know Ant? All the Maven Ant plugin is doing is calling Ant with the tasks you list. You can do any Ant task including <taskdef>, etc.

是什么样子,你正在做的可以用文件集来完成:

What it looks like you're doing can be done with fileset:

 <copy todir="${swf.output.location}">
    <fileset dir="${project.build.directory}">
        <include name="*.swf"/>
    </fileset>
</copy>

这将直接复制在位于所有 *。SWF 文件中的 $ {project.build.directory} (没有子目录)到 $ {swf.output.location} 目录。如果你要复制的 * SWF 文件整个目录树,只是改变了&LT;包括&GT;

This will copy all *.swf files located directly under in the ${project.build.directory} (and no subdirectories) to the ${swf.output.location} directory. If you want to copy the entire directory tree of *.swf files, just change the <include>:

 <copy todir="${swf.output.location}">
    <fileset dir="${project.build.directory}">
        <include name="**/*.swf"/>  <!--NOTE DIFFERENCE HERE-->
    </fileset>
</copy>

如果您需要munge文件名,则可以使用映射器。最简单的映射是扁平化映射:

If you need to munge the file names, you can use Mappers. The simplest mapper would be the flatten mapper:

 <copy todir="${swf.output.location}">
    <fileset dir="${project.build.directory}">
        <include name="**/*.swf"/>  <!--NOTE DIFFERENCE HERE-->
    </fileset>
    <mapper type="flatten"/>
</copy>

这将复制整个目录树中的所有文件压扁成一个单一的目录中。有可以匹配的水珠,定期EX pressions,甚至脚本映射器。

This will copy the entire directory tree and flatten all the files into a single directory. There are mappers that can match globs, regular expressions, and even scripting.

&LT;&包括GT; 是一个选择,而不是一个映射器,因为它选择您想在采取行动哪些文件。这些也可以说是相当复杂的,可以匹配根据他们的名字经常IVA前pressions,甚至他们的内容的文件。

The <include> is a selector and not a mapper because it selects what files you want to act upon. These too can be quite complex, and you can match file based upon their names iva regular expressions, or even their contents.

我很惊讶,没有一个Maven插件,可以让你做到这一点。

I'm surprised there isn't a Maven plugin that allows you to do this.

这篇关于Maven和Ant的插件,能够智能地复制资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆