I am trying to get files from FTP, it always says no files retrieved,
here goes my code
<target name="ftp">
<ftp action="get"
server="${myftpserver}"
userid="${username}"
password="${password}"
remotedir="a"
binary="no"
verbose="yes"
passive="yes">
<fileset dir="abc" includes="CatalogReferenceAttribute.java"/>
</ftp>
</target>
Here i am trying to retrieve a .java file from FTP folder
a
to my local folder
abc
below is my ouput
Where i was wrong?
Did you put the dependency libraries into ANT's lib directory?
common-net.jar may not be enough... check this page:
http://ant.apache.org/manual/install.html#librarydependencies
Related
I am trying to retrieve the list of all zip files present in a directory.
I have a directory ${src} which contains some zip files and I am using the following code
<target name="test">
<dirset id="dist.contents" dir="${src}" includes="*.zip"/>
<property name="prop.dist.contents" refid="dist.contents"/>
<echo message="${prop.dist.contents}" />
</target>
but it only echoes null.
I also tried includes="*" but it didn't make any difference.
I am using Ant version 1.7.0.
As written in the documentation:
A DirSet is a group of directories.
So since you want zip files, you should use a FileSet.
I have a java project (MyProject) with the below mentioned structure
src->package1(read as com.test.Atrribute)->File1.java,File2.java
src->package2(read as com.test.Objects)->obj1.java,obj2.java
src->directory(read as Webcontent.Objects)-> Folder1 -> application.properties file and some more files
Currently the build.xml creates a jar for the above project and copies the class files from package1 and package2.
However, my jar should also include the folder(Webcontent.Objects) with all the content's within it (i.e folders and files).
How can I do this in the build.xml ?
I have never created a build.xml before and pretty much new to all this.
Following is the jar task in the build.xml to include the class file's in the jar.
<target name="MyProject-jar" depends="compile"
description="Jar for the Project">
<jar destfile="${output.dir}/MyProject.jar" basedir="${output.dir}/">
<include name="com/test/Attribute/*.class"/>
<include name="com/test/Objects/*.class"/>
</jar>
</target>
Appreciate if anybody could help.Thanks.
You could add
<include name="Webcontent/Objects/**/*"/>
to your jar task
Note: The ** recursively considers directories under its parent
I am looking forward for an example which unjars a file referenced from the classpath inside the ANT. I couldn't find any example in the web. When I tried using the path inside the unjar target, it unjars all the jar files inside the classpath. Can anyone suggest me something giving some example ?
You have to specify the jar name which you what to unjar.
Probably you have wildcard(*) in your src
This will unjar all jars in ${ant.home}/lib/
<unzip src="${ant.home}/lib/*.jar" dest="..."/>
I think you should use:
<unzip src="${ant.home}/lib/ant.jar" dest="..."/>
If you want to unjar some files from your jar look at this example:
<unzip src="${ant.home}/lib/ant.jar" dest="...">
<patternset>
<include name="**/ant_logo_large.gif"/>
<include name="**/LICENSE.txt"/>
</patternset>
</unzip>
Look at unzip task documentation
Is there a way I can modify a file in a jar using ant script. Like, I have a x.properties in a y.jar. I want to edit this x.properties and put it back into the y.jar using ant script. Is this possible?
To extract a file from a jar:
<unjar src="y.jar" dest="build">
<patternset>
<include name="x.properties"/>
</patternset>
</unjar>
To add it back in:
<jar jarfile="y.jar" update="true">
<fileset dir="." includes="x.properties"/>
</jar>
jar -xvf <filename> extracts a file out of a jar.
jar -uvf <filename> can update a file in the jar.
You can use a script to do this and then use Ant to call the script.
I usually unpack the whole jar file, alter the file I want to alter, and then create a new jar file. I is probably not the fasted way, but my build scrips are not time critical.
I am a bit of an ant newbie, and I'm having trouble making a jar correctly. As an example, say I want to make a jar with my StringUtil class. Using the following ant directive, I can create the jar, but the problem is that the directory structure is lost. It simply puts StringUtil.class in the base directory of the jar. How can I correct this ant directive so that StringUtil.class is inside the com/test directory in the jar?
<jar destfile="myjar.jar" >
<fileset file="${build}/com/test/StringUtil.class"/>
</jar>
Thanks!
You need to tell Ant to build the jar from the base directory, then tell it to include only the desired file. Like so:
<jar destfile="myjar.jar" >
<fileset dir="${build}" includes="com/test/StringUtil.class"/>
</jar>
Here's the doc for <fileset> tags.