How to copy files into a zip file using ANT script? - ant

I want to copy few files into an existing zip file using ANT script.
Is there any task available for that? Or do I need to unzip the zip file then copy the needed files and zip again?

Straight from the documentation of the zip task:
The update parameter controls what happens if the ZIP file already
exists. When set to yes, the ZIP file is updated with the files
specified. (New files are added; old files are replaced with the new
versions.)

If you have an existing zip file called perlscr.zip, you can add for example, a file called backup.sh in the shellscr directory using the Ant Zip task:
<zip destfile="perlscr.zip"
basedir="shellscr"
includes="backup.sh"
update="true"/>

Related

Zip Pipeline Utility - Recursively Zip Sub Dir and Files

Can I use this utility to recursively zip files and sub-dirs under a dir?
As specified in the documentation , if I do not set value for "glob" , all the files and dirs are getting included as part of the zip file.

Zip all the files within the folder in jenkins workspace

I have some files in Jenkins work space. I want all the files to be zipped and zip should now include the root folder and should include only the contents within the folder.
I have already tried using file operation plugin which actually zips the files. But problem using this plugin is that all the files are inside an root folder. What i need is as soon as i unzip i should only get the files and not the folder.
Try and use the manven assembly plugin.
You can then configure it to include file without taking its path folders, using:
<includeBaseDirectory>false</includeBaseDirectory>-
fileSets
You can simply do it using terminal
got to the root directory or the directory that have all the files you want then :
tar chvfz workspace.tar.gz *
will zip all the files in the workspace in workspace.tar.gz
if you wanna zip specific files u can list them instead of using *

How to use ant unzip to include nested zip file?

I have an ear file which includes war files and jars.
I'm using the unzip task to unzip the ear.
the problem is that I want to see in my destination folder the war files etracted as well.
for eample:
I have c:\example.ear inside i have 1.jar, 2.jar 3.war, 4.war
after extractio I would like to see:
c:\exmple
3.war (d)
4.war (d)
1.jar (f)
2.jar (f)
when d=directory f=file
well, apperantaly you cannot create a folder with the same name of a war file in the same location.
So what I did in the end was move the war file to a tmp folder and unzip from there to the previous location.
solve the trick :-)

How do I modify a file in a jar file using ANT?

I need to update an XML file that's inside of a jar file using ANT. I have to search for a string in the file and replace it with another value if that string exists.
A crude approach. Unzip the jar file, use the replace ant task, zip the files again and put the jar file back.
Task: copy
Task: unzip
Task: replace
Task: zip
Task: move

Delete generated files when original is modified with Apache Ant

I want to delete the generated files (".tmp" and ".bak") in the build directory when the source file (".xml)" is modified with Apache Ant. All files have the same name, but different extentions.
I'm not able to create the fileset to do this.
You can use a file mapper in place of a fileset.

Resources