I am using ant to build my application with timestamp. It is running currently. Now i want to get the latest updated folder so that i can copy that to any other folder.
I tried and it is printing me the latest file only but its not copying that file to another folder.
Please help me
<tstamp>
<format property="timestamp" pattern="dd-MMM-yy" locale="en,UK"/>
</tstamp>
<timestampselector property="latest.modified">
<path>
<fileset dir="${Engine.stagging.dir}">
</fileset>
</path>
</timestampselector>
<copy todir="${prjHop.release.dir}" flatten="true" overwrite="true">
<fileset dir="${Engine.stagging.dir}">
<include name="${latest.modified}"/>
</fileset>
</copy>
Also tried this to copy
<copy todir="${prjHop.release.dir}">
<path refid="${latest.modified}"/>
</copy>
<echo message="${latest.modified}" />
this echo is printing current folder and file name. I just want to copy the file inside that folder.
Thanks
The ${latest.modified} contains the absolute path of the file. When you use this path in the include nested element, the copy task will not find the file in the directory specified in ${Engine.stagging.dir} and hence will not copy it.
You can do the copy as follows:
<copy file="${latest.modified}" todir="${prjHop.release.dir}"/>
Related
Based on this topic: Netbeans and external configuration files
I assume that what I want to do this is possible. But the answer is not really working for me.
The code is use know is from the last answer:
<target name="-pre-jar">
<echo>Copying resources files to build directory...</echo>
<mkdir dir="${dist.jar.dir}/resources"/>
<copy todir="${dist.jar.dir}/resources">
<fileset dir="resources" includes="**"/>
</copy>
</target>
But this just creates a dir named: ${dist.jar.dir} with my resources folder and files in it at the same location of my src,dist,build,nbproject folder. But I want it to be in dist, so my dist has, the jar, lib,webfiles and resources.
Thanks for any help and clarification.
If you want to copy all the contents of a specific directory to the \dist directory of the build you can do the following:
<target name="-pre-init">
<!-- Create a resource directory property -->
<property name="src.res.dir" value="${basedir}/res" />
</target>
<target name="-pre-jar">
<!-- Copy external resources folder -->
<copy todir="${build.classes.dir}\inside\res\dir">
<fileset dir="${src.res.dir}\inside\res\dir">
<include name="**/*" />
</fileset>
<copy>
</target>
This will copy the contents of a folder called \inside\res\dir inside of your projects $\res directory. I use this technique to include an application icon in the distribution.
You should then be able to access these resources from inside your application with something like the following:
ClassLoader.getSystemResource("inside/res/dir/file.ext")
Okay I solved it, so to copy a file, I placed the file in in a folder within src named resources with in there my file.
And then the following code does the trick:
<target name="-post-jar">
<copy file="${src.dir}/resources/filename.extension" flatten="true" todir="${dist.dir}/resources" />
</target>
Okay, for some reason my jar isn't being builded/updated any more if I use this in my build file..Anyone any clues?
solved needs to be "-post-jfx-jar" for jfx projects
Say I have directory structure like this:
base_dir1/src_dir
base_dir2/dest_dir
How do I copy src_dir(folder + contents) into dest_dir.
If I use copy task like this:
<copy todir="base_dir2/dest_dir">
<fileset dir="base_dir1/src_dir"/>
</copy>
It will copy all the contents of src_dir into dest_dir, but will not create a src_dir folder inside dest_dir.
I can make it work by using the copy task like this:
<copy todir="base_dir2/dest_dir">
<fileset dir="base_dir1">
<include name="src_dir/"/>
</fileset>
</copy>
Is this the correct way or is there a better way to do it?
Alternately, you could do this.
<copy todir="base_dir2/dest_dir/src_dir">
<fileset dir="base_dir1/src_dir"/>
</copy>
The folder (or part of the folder) specified by todir need not exist.
<fileset> refers to contents of the specified folder (excluding it).
I'm sure this has either been asked before or is pretty straightforward. But for whatever reason, I cannot seem to make it work. I want to use ant to copy the ${build.classpath} (which contains a colon separated list of jars) to the ${output.dir}/myapp/WEB-INF/lib.
I have this right now and it doesn't seem to work:
<copy toDir="${output.dir}/myapp/WEB-INF/lib">
<fileset file="${build.classpath}" />
</copy>
It treats the whole classpath as one file. How do I get this to work?
The Ant Manual on the copy task contains the answer for your problem. One of the example snippets it provides:
Collect all items from the current CLASSPATH setting into a destination directory, flattening the directory structure.
<copy todir="dest" flatten="true">
<path>
<pathelement path="${java.class.path}"/>
</path>
</copy>
I think somethink like this should work:
<copy todir="${output.dir}/myapp/WEB-INF/lib" verbose="yes" flatten="yes" failonerror="no">
<fileset dir="${build.classpath}">
<include name="*.jar" />
</fileset>
</copy>
or with wildcard in include: <include name="**/*.jar" />
I think you should put all your colon separated jar files to one root folder. If it is not possible then create a separate task that put those jar files into one folder(may be temporary). And assign ${build.classpath} to that folder. Use <fileset dir="${build.classpath}"/> in your copy clause.
I hope, it should help.
In my build.xml, below works fine :-
<path id="build.classpath">
<fileset dir="lib [myUtils]" includes="*.jar" />
</path>
if lib [myUtils] is of folder type, but don't works, if it's of Linked Folder type.
Also, I found this when googled :-
https://bugs.eclipse.org/bugs/show_bug.cgi?id=265960
https://bugs.eclipse.org/bugs/show_bug.cgi?id=43081
https://bugs.eclipse.org/bugs/show_bug.cgi?id=265960
Is there any trick to achieve this, without copying the dependencies in work folder??
Note that ant should work outside of eclipse as well. So you can't reply in IDE abstractions. You can use symbolic links (if your OS supports them).
If not, you can use the FileSync plugin to synchronize eclipse project folders with external folders. Or you can simply use the <copy> ant task.
I resolved this using copy task:
<copy todir="target/web/linked1">
<fileset dir="../linkdProject/source1" />
</copy>
<copy todir="target/web/linked2">
<fileset dir="../linkedProject/source2" />
</copy>
....
<war destfile="target/webApp.war">
<fileset dir="WebContent" />
<fileset dir="target/web" /> <!-- copy linked resources -->
...
</war>
<delete dir="target"/>
Is there a way to delete duplicate files using ant? Specifically, if I have the same file name in two different output directories, I want to delete it from the second directory.
I think I came up with a solution.
<target name="delete-duplicates">
<delete>
<fileset dir="delete-here" includes="**/*">
<present targetdir="if-present-here" />
</fileset>
</delete>
</target>