How do I modify a file in a jar file using ANT? - 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

Related

How extract the .rar files through ANT script

How to Extract the .rar files through ANT script and multiple files?
I don't think there's anything native in ant or Java to handle RAR files. Maybe you can <exec> the unrar command from here?

Creating SAR file with Ant

I am reworking a build, and notice that the ear file contains a Service archive file (sar). I'd like to build the sar file in Ant. I suspect I could probably use the ear or zip task to do this, and simply name the file as *.sar. However, I want to be sure that this will work.
What task would I use in Ant to create a SAR file?
It seems you should use the standard JAR task in ANT. According to the JBoss documentation, SAR files contain an extra file:
META-INF/jboss-service.xml
The following "hello world" example has a sample project attached:
https://community.jboss.org/wiki/ExampleHelloWorldService
A sar file is a special kind of jar file (with certain files in WEB-INF, etc.). So you can use the jar task, e.g.:
<jar destfile="${sar.filename}">...</jar>

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

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"/>

give input to a runnable jar file through a file

I have created a jar file using ant. I want the jar file to take input from a external file.
How can we achieve this?
The java task has an input attribute that specifies the file that should be used as stdin.

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