Delete generated files when original is modified with Apache Ant - 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.

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 Include a folder and files in META-INF folder when creating the jar using ant task

I need a way to include a folders and files inside the META-INF directory when creating a jar using ant task.
Currrently I am using <metainf> tag , which is only including the files but not the folders.
Can anyone please help me.
Add new folder TEMP-INF under src\main\java
Put all the files and folders, which you wish to include in your JAR's META-INF into this newly created TEMP-INF
Now open build.xml file and search for
<jar> </jar> tag
Add <metainf dir="src/main/java/TEMP-INF"/> into <jar></jar>
And its done.

Create war without manifest

I need to create a war file through ant build without a manifest file. I want the war to me created without the manifest file.
I am using tag in build.xml to create the war.
you can use <zip/> task with .war extension for destfile attribute to achieve the same result as the <war/> task (without manifest.mf).
<zip destfile="..\...\WarFile.war"basedir="..\basedir" update="true"/>
in case WarFile.war already exists, although you've written I need to create a war file , the attribute update="true" will be of use (by only updating and not overwriting the file).
All a war file is is a zip file in a specific format. That is libraries go in a particular place, class files go elsewhere, etc. The <war> task has sub-entities like <classes/> and <lib> that make configuring a war file correctly without knowing exactly where everything has to go.
However, you can correctly format the war yourself, and use <zip/>.
Why don't you want a manifest file? A manifest, if you don't specify anything, will contain nothing but the Java version used for the build, and the Ant version and won't affect the execution of your war at all.
What you can do is put useful information into the manifest. For example, we use Jenkins for our builds, and we put in the Jenkins project name and the build number which helps us understand what was included in the war.
There's no reason not to use a manifest file. And, a manifest file can contain useful information (which is accessible to the Java program too).

How to rename a file for a specific maven build profile

I've got changes to my web.xml config file that need to stay local-only since Google-App-Engine chokes on them when we try to use them, and they're really only needed for development purposes.
How can I make maven copy my src/main/webapp/WEB-INF/web_local.xml to be web.xml in the target WEB-INF directory?
I looked into maven-assembly-plugin, but that didn't provide a way to give a name to the ouput file (plus it seemed specifically for building .jar files).
You can use webXml property of the maven-war-plugin plugin configuration to point to custom web.xml

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.

Resources