How to copy a directory using Ant

前端 未结 11 1146
挽巷
挽巷 2020-12-13 08:49

I have used copydir to copy a directory tree but it is deprecated. My directory contains some sub-directories, and some of those contain files and others contai

相关标签:
11条回答
  • 2020-12-13 08:54

    This code should copy the folder as well as its contents. It also uses the basename task to avoid having to do any manual path parsing.

    <project name="Build" default="doCopy">
      <property name="source.dir" value="SourceDirPathGoesHere"/>
      <property name="dest.dir" value="DestinationDirPathGoesHere"/>
      <target name="doCopy">
        <basename property="source.dir.base.name" file="${source.dir}"/>
        <copy todir="${dest.dir}">
          <fileset dir="${source.dir}/.." includes="${source.dir.base.name}/**"/>
        </copy>
      </target>
    </project>
    
    0 讨论(0)
  • 2020-12-13 08:56

    I finally copied using following code

    <copy todir="${root.dir}/dist/src">  
                    <fileset dir="${root.dir}/build/src" includes="**"/>  
                </copy>
    

    This will copy the src folder from dist to build.

    Hope this helps someone.

    0 讨论(0)
  • 2020-12-13 08:57
    <copy todir="${dest.dir}" >  
        <fileset dir="${src.dir}" includes="**"/>  
    </copy> 
    

    believe that will do what you want... (Recursive copy done)

    0 讨论(0)
  • 2020-12-13 08:59

    Another ant task is Copydir. The key part here is to include the name of the directory you want to copy after the dest directory. The sub-directories and files will be copied automatically.

    <target name="-post-jar">
        <copydir src="config" dest="${dist.dir}/config/"/>
    </target>
    
    0 讨论(0)
  • 2020-12-13 09:03

    Copy contents including the directory itself.

    <copy todir="${dest.dir}" >  
      <fileset dir="${src.dir.parent}" includes="${src.dir}/**"/>
    </copy>
    
    0 讨论(0)
  • 2020-12-13 09:04

    I used include tags as shown in below code snippet in my build.xml file to copy individul jar files inside a directory.

    <target name="devInstall" depends="generateXsl" description="testing">
    <copy flatten="true" todir="${test}/WEB-INF/lib" overwrite="${overwrite}">
                    <fileset refid="buildJars"/>
                    <fileset dir="lib">
                        <include name="commons-collections-*.jar"/>
                        <include name="commons-io-*.jar"/>              
                        <include name="kodo/*.jar"/>
                        <include name="mail*.jar"/>    
                        <include name="activation*.jar"/>               
                        <include name="guava*.jar"/>
                        <include name="jna*.jar"/>                          
                    </fileset>          
                </copy>
    </target>
    
    0 讨论(0)
提交回复
热议问题