adding the specified folders in the jar created using ant - ant

I have a folder structures
build/classes/com/vaannila/domain/.class files
build/classes/com/vaannila/service/.class files
build/classes/com/vaannila/web/.class files
My requirement is to create a jar file using ant, how can I include the specified folders in the jar,say I want include only domain and service (or) domain and web in the jar, like the way I create the jar using Eclipse(Export-->archive file).
Can anyone help me with this please?

You can use include and exclude tags in the fileset element, and choose specific files...
<jar destfile="${jar.dir}/${jar.file.name}" index="true"
manifest="${manif.dir}/${manif.file.name}">
<fileset dir="${build.classes.dir}" >
<include/>
<exclude/>
</fileset>
</jar>
<fileset dir="${build.classes.dir}">
<exclude name="**/property/*"/>
<include name="**/abcd/*"/>
</fileset>
This way you can remove/include respective directories.

Related

Can I use an Ant fileset as input to construct another fileset?

I am automating a build process using Jenkins and Ant build steps. I have the build operation and post-build source control tagging working fine.
After a number of QT projects have been built, I want to be able to preserve the useful artifacts from the build.
As a vehicle for discussion/consideration, lets say I have the following set of files in a build directory:
MyApp.exe
MyApp.pdb
MyApp_Tests.exe
MyApp_Tests.pdb
SomeLib.lib
SomeLib.pdb
3rdParty.lib
3rdParty.pdb
Utils.dll
Utils.pdb
(In reality there are many more exe's, dll's lib's and their associated pdb files and the files produced by the build change frequently as the project evolves.)
I want to collect the "deliverable" files (non-test exe's and dll's) and their pdb files without the test exe's, lib files and their pdb files.
I believe I can get a fileset of the deliverable files to use in a copy task:
<copy todir="${artifactDestination}" failonerror="true">
<fileset dir="./build">
<include name="*.exe" />
<include name="*.dll" />
<exclude name="*_Tests*" />
</fileset>
</copy>
What I am struggling with is how to get a fileset of the pdb files that relate to the exe and dll files, i.e. all the pdb files except MyApp_Tests.pdb, SomeLib.pdb and 3rdParty.pdb.
What I would like to do is use the initial fileset of exe and dll files and create a second fileset from that which has those filenames with a .pdb extension instead of .dll or .exe.
I've been reading up on selectors and such but have not managed to spot a solution to achieve my desired result.
Any suggestions?
You should be able to achieve what you want with two subsequent copy tasks. The first one is the one you've already figured out. In order to copy the .pdb files that match the files you've copied in the first step you can use a present selector.
<copy todir="${artifactDestination}" failonerror="true">
<fileset dir="build">
<or>
<present targetdir="${artifactDestination}">
<globmapper from="*.pdb" to="*.exe"/>
</present>
<present targetdir="${artifactDestination}">
<globmapper from="*.pdb" to="*.dll"/>
</present>
</or>
</fileset>
</copy>

How do you create a classpath in ANT that includes all jars in a directory and it's subdirectories

I'm using ANT to build a Java project that has dependency jars during compile time. The dependency jars are nested inside a directory. What this means is, the directory contains sub-directories (which might contain sub-directories) and jars as well.
I want to create an ANT element to include all the jars inside the directory. Below is my code but doesn't work. I'm wondering if this can't be done in ANT or I'm doing something wrong:
<path id="javaee.classpath">
<fileset dir="${javaee.modules.dir}">
<patternset>
<include name="**/*.jar" />
</patternset>
</fileset>
</path>

Remove fileset directories from Ant war lib

Is there a simple way to use Ant <mappedresources> to flatten directories in a <fileset> into a <war> <lib>. For example:
<fileset id="xx.lib" dir="${base.lib.path}">
<include name="library1/library1.jar"/>
<include name="library2/library2.jar"/>
</fileset>
So that the jars are in WEB-INF/lib without their "library1"/"library2" paths.
I have read the above link and several related questions here on SO, but I can't envision the mechanism to do exactly what I'm describing, for just one of several <lib> elements.

Apache Ant create new fileset from existing fileset with filenames renamed

I have the following fileset in my Apache Ant build file (BuildFilesetXML.xml):
<fileset id="XMLFileset" dir="mydir/myxml">
<include name="**/1.xml"/>
<include name="**/2.xml"/>
</fileset>
I want to create dynamically in a different build file (BuildFilesetLog.xml) (do not know the contents of "XMLFileset" in my 2nd build file) a new fileset named "LOGFileset" that will have the same contents of "XMLFileset" but with names renamed to .log. So, in runtime it will have the same structure as the following fileset:
<fileset id="LOGFileset">
<include name="**/1.log"/>
<include name="**/2.log"/>
</fileset>
Can this be done in Ant?
Thanks
No, but some tasks support mappers. For an example see the following answer:
Change directory of FileList when referencing it

Apache Ant: Selecting files with fileset?

It's really easy to select a file with a specific filename, or filetype using fileset in ANT, however I have yet not figured out how to write a fileset that remove all files with a filename beginning with a dot, such as .builtpath, and .hgignore, but excluding .htaccess;
Here's my current file:
<delete includeemptydirs="true">
<fileset dir="${temp.dir}/fromRepo">
<exclude name=".htaccess"/>
<include name="**/*" /> <!-- How to select files starting with .?!-->
</fileset>
</delete>
Suggest you try:
<delete includeemptydirs="true">
<fileset dir="${temp.dir}/fromRepo">
<exclude name="**/.htaccess"/>
</fileset>
</delete>
If you don't specify any wildcard - as in ".htaccess" then that rule will only match the exact file name, i.e., '.htaccess' in the top-level directory of the fileset. Prepending the directory wildcard ** to .htaccess will tell Ant to exclude from the delete all files called '.htaccess' found under the directory hierarchy of the fileset.
There's an implicit include of all files if you don't specify any include rule - so no need to specify the 'global' include.
One thing to watch out for - setting includeemptydirs true will remove any empty directories when using a fileset with the delete task. A directory will only be considered empty if it doesn't contain any files. In other words: directories containing a file called '.htaccess' will not be deleted, but those with a '.htaccess' file will not be deleted - hope that's what you need.

Resources