How to use ant unzip to include nested zip file? - ant

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 :-)

Related

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

How should the log4j.properties put inside the war file using ANT build tool?

I have a log4j.properties that sit right under the src folder. When I building my war file using ANT tool, the particular properties file wasn't pack inside WEB-INF/classes folder, and it was right under the "root" directory of the war file (if you unwar it). I heard from my colleague mention that this is not correct. May I know is this true? If no, how should I correct it?
THanks #!
Yes, log4j.properties (or any other resource loaded from the classpath) should be at the root of your Java source folder (src/main/java, build/main, src, JavaSource, or however you have your project configured).
In the WAR, it should be under WEB-INF/classes, not at the root (as if you unzipped it).
If this is not the case, being able to see your ANT build file would be very helpful. You should have something like this line configured within your war task:
<classes dir="build/main"/>
As long as you have a build/main/log4j.properties in your Ant basedir, this should work as you're expecting.

Separate same jars in different WAR of a EAR

currently we are facing one problem. We are building a ear which contains multiple war files. In 2 of the WARs contains same jars. Both these wars need these jars during deployment.So Is there any way in ANT I can built it so that these jars will be in one single place and it will not create any problem during the ear deployment.
well, you can do it the portable way:
Place the library jars at the root of .ear file.
Example:
library jar -> lib1.jar, lib2.jar
[EAR STRUCTURE]
your.ear
|--yourfirst.war
|--yoursecond.war
|--lib1.jar
|--lib2.jar
Update the MANIFEST.MF files in both the .war files to point to these jars
like so:
Class-Path: lib1.jar lib2.jar
(dont forget to add a space and a newline character to the end of the above line if this is the last entry in the manifest)
You can put those shared JARs into the EAR's lib directory. Those will then be available on the classpath for any WARs in that EAR.

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