I want to copy a jar file from ../source,but I am not sure where it exactly is,it can be anywhere in any subdirectory but it is there. I am writing this code
<target name="CopyingFromSource" depends="clean">
<copy file="../source/org.springframework-spring-support-2.0.8.jar" todir="../result"/>
</target>
but is showing me can't find org.springframework-spring-support-2.0.8.jar Can you please tell me how to copy it?
It is present anywhere either immediately in /source or in any subdirectory.
Use copy task with nested fileset like that :
<project>
<copy todir="../result">
<fileset dir="/home/gilreb/temp" includes="**/org.springframework-spring-support-2.0.8.jar" id="foobar"/>
</copy>
</project>
see Ant manual copy task and Ant manual fileset for turther details.. i.e. if you need to copy the flat file only and not it's whole path you need to use :
<copy todir="../result" flatten="true">
...
</copy>
Related
I am facing issue while copying directories from source to destination in ant build file.
code:-
<target name="getResources" depends="init">
<delete dir="${resources.dir}"/>
<copy file="${svn.resources.url}" tofile="${resources.dir} " />
</target>
Error:-
build.xml:150: Use a resource collection to copy directories.
Please suggest me how to copy directory from source to destination. I used several ways...like
<export srcUrl="" destPath=""> this is also saying deprecated and used and also. but none of the properties are working. Please suggest me how to do.
<!-- copy one file -->
<copy file="/home/guest/workspace/so/src/build.xml" tofile="/home/guest/workspace/so/src/build2.xml" />
<!-- copy a folder recuresively -->
<copy todir="/home/guest/workspace/so/src2">
<fileset dir="/home/guest/workspace/so/src" includes="**" />
</copy>
you also may want to look at copy task documentation and examples here
I want to use ant script to copy a file to directory which is not path is fixed but last folder name is not fixed.
Path D:\Home\Config\plugins\1780.
The last folder name (1780) it changes randomly and is not fixed.
I want to copy a war file in to that folder.
How can I do it.
Thanks,
Prashant
You should iterate (once) over plugins subdirectories and copy to the (only?) entry.
<target name="run">
<foreach target="loop" param="loop.param">
<dirset dir="D:\Home\Config\plugins" />
</foreach>
</target>
<target name="loop">
<copy todir="$loop.param">
...
</copy>
</target>
I am trying to use ant to copy files from sourceDir to destDir, and I also don't want to copy some files, I keep the file names I want to exclude in file: excludelist.txt. How could I implements this is an ant target ?
Use copy task with nested fileset using nested exludesfile.
From ant manual FileSet :
excludesfile => the name of a file; each line of this file is taken to
be an exclude pattern.
snippet :
<target name="foo">
<copy todir="path/to/destDir">
<fileset dir="path/to/sourceDir">
<excludesfile name="excludelist.txt"/>
</fileset>
</copy>
</target>
I'm facing a problem with ant "copy". Here is my requirement:
I want to sync 2 dirs(dir1 and dir2) but i want to keep the extra files/dirs present in dir2. My aim is i want to copy dir1 contents(if modified ) to dir2 but want to keep any additional files/dirs present in dir2.
I tried ant's sync task, but it is trying to keep both dirs in sync ie., it is deleting extra contents present in dir2. I don't find any flag to disable this feature:
<sync todir="dir2" failonerror="true" verbose="true">
<fileset dir="dir1" excludes="*.svn" />
</sync>
I tried ant's copy with "modified" selector, but its also doing the same: :(
<copy todir="dir2" failonerror="true">
<fileset dir="dir1" excludes="*.svn" >
<modified/> <!-- Copies only modified files -->
</fileset>
Can any one suggest, how can i achieve my requirement with ant?
By default, the ANT copy task does not overwrite files:
<copy todir="target/dir2" verbose="true" overwrite="false">
<fileset dir="src/dir1"/>
</copy>
The copy task will also detect if the file has changed.
The copy task will not delete files, so I don't understand why your second example (using a modified selector) did not work.
Suppose I have a directory structure like the following
/a/b/testB.xml
/a/c/testC.xml
/a/testD.xml
and I want to copy everything inside /a to /build
so that I will have
/build/b/testB.xml
/build/c/testC.xml
/build/testD.xml
What ant command should I use? I have tried using fileset and it looks like that it only copies the files that are specified in the includes to the todir directory.
Try this:
<copy todir="build">
<fileset dir="a">
<include name="**/*"/>
</fileset>
</copy>
The docs on FileSet are here.