通过比较文件中的文件,将文件夹中的所有文件复制到另一个文件夹中

时间:2016-04-01 16:33:30

标签: maven ant maven-antrun-plugin

我们如何通过比较该文件夹中的所有文件将所有文件从一个文件夹复制到另一个文件夹,如果文件内容已更改,则将文件复制到另一个项目位置,否则不会。

有任何建议我应该尝试哪个插件吗?

我正在尝试使用maven-antrun-plugin(版本1.7)但尚未成功。

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-antrun-plugin</artifactId>
       <executions>
        <execution>
            <phase>initialize</phase>
                <configuration>
                    <target name="main">
                        <ant antfile="/build.xml" target="main" />
                     </target>
                </configuration>
                    <goals>
                         <goal>run</goal>
                     </goals>
         </execution>
       </executions>
   <dependency>
       <groupId>ant-contrib</groupId>
      <artifactId>ant-contrib</artifactId>
     <version>1.0b3</version>
 </dependency>

</plugin>

1 个答案:

答案 0 :(得分:0)

我可以通过使用maven-antrun-plugin

来完成
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <configuration>
                            <target name="build">
                                <ant antfile="build.xml"
                                    target="build" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>1.0b3</version>
            <exclusions>
              <exclusion>
                <artifactId>ant</artifactId>
                <groupId>ant</groupId>
              </exclusion>
            </exclusions>
          </dependency>
        </dependencies>
            </plugin>

的build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="prospector" basedir="/" default="main">
<target name="main" depends="etc"/>

<target name="etc">

        <for param="file">
            <path>
                <fileset
                    dir="etc"
                    includes="**/**" />
            </path>
            <sequential>
                <var name="name" unset="true" />
                <basename file="@{file}" property="name" />
                <if>
                    <filesmatch file1="@{file}" file2="etc/${name}" /> 
                    <then>
                        <echo message="There is no change in ${name}" />
                    </then>
                    <else>
                        <echo message="There are some changes in ${name}" />
                        <copy
                            file="@{file}"
                            tofile="etc/${name}" overwrite="true"/> 
                    </else>
                </if>


            </sequential>
        </for>
    </target>