Including Websphere's ibm-application-ext.xml file in an ant build script - ant

Problem:
We have a Websphere EAR project. Under it are two web modules. These two web modules make use of the same shared session context. This in enabled by setting in it the ibm-application-ext.xml file of the ear project.
I know how to create an ant build script to create an .ear file. The thing is, I do not know how to include ibm-application-ext.xml in the ant script to have it included in the .ear file . How do I do that?
If the application.xml file is included through the ff. syntax below, how to I include ibm-application-ext.xml.
<ear destfile="somearfile.ear" appxml="conf/application.xml">

If it's stored in conf/application.xml, then something like this:
<ear destfile="somearfile.ear" appxml="conf/application.xml">
<zipfileset dir="conf" includes="ibm-application-ext.xml" prefix="META-INF"/>
</ear>
...or just:
<jar destfile="somearfile.ear">
<zipfileset dir="conf" includes="*.xml" prefix="META-INF"/>
</jar>

Related

Ant Task to FTP only specified files

I have an Ant task that FTPs all files in a specified directory, and it uses a fileset:
<fileset dir="${publicDirectory}">
<include name="media/**/*" />
</fileset>
I have a file that contains all the files that I would like to include:
media/some/dir/1.txt
media/some/other/2.txt
...
How can I have the fileset read the file and only include whatever I've listed there?
I've tried quite a few things, but nothing seems to be able to get around a basic issue: The <ftp> task works only on filesets and not other types of resources. I've tried various filterchains, but to no avail.
The best I could come up with was using the Ant-Contrib <for> or <foreach> task to loop through the file and then use an <exec> task to execute the command line version of ftp.

Is there a way in ANT to extract one class file from a JAR and put it in another JAR?

My ANT build script uses a WebSphere command called createEJBStubs that produces a JAR file with everything plus one new generated class, namely: com/myapp/services/_User_Service_Stub.class.
Since this stub class is only used for running JUnit tests at dev time, I would like it to be in its own JAR file.
How can I tell ANT to copy everything in AAA.JAR that matches, say, _*Stub.class and copy only those files into BBB.JAR (also, maintaining the same directory/package structure)?
Any ideas or pointers would be GREATLY appreciated! Thanks,
Rob
Ok -- answering my own question -- that was surprisingly easy. Sorry I asked.
<unzip src="AAA.JAR" dest="./temp">
<patternset>
<include name="**/_*Stub.class" />
</patternset>
</unzip>
<zip destfile="BBB.JAR" basedir="./temp" />
Thanks ANT.

listing all files and subdirectories using ant

I am trying to create a rpm package using ant task for that I need to create specfile which will have all the file names in the following format
%attr(0755, root, root) %dir dir1
%attr(0755, root, root) %dir dir1/dir2
%attr(0755, root, root) %dir dir1/dir2/dir3
%attr(0500, root, root) dir1/file1
%attr(0500, root, root) dir1/dir2/file1
I have such directory structure created during my build process but using ant I am not able to list all the files and directories which I can then write into my specfile
following is what I have tried to list the files but it does not differentiate between files and directory , moreover I need some way to iterate over the list.
<fileset id="dist.contents" dir="${nativePackageDir}" includes="**"/> |
<property name="prop.dist.contents" refid="dist.contents"/> | <target name="javaobject-library" depends="props">
<echo>${prop.dist.contents}</echo>
<dirset id="dist.contents" dir="${nativePackageDir}" includes="*"/>
<property name="prop.dist.contents" refid="dist.contents"/>
<echo>${prop.dist.contents}</echo>
Using dirset instead of fileset should fix your problem.
You simply have to write in java an ant task implementation, to which you'll provide as parameters the input directory and the path of the specfile you want to be written.
I find it better and more manageable to have reusable ant tasks in java, instead of having gigantic ant xml files.

How to tell MSBuild where to put my compiled files?

I'm trying to use Nant to compile an ASP.NET MVC app, so far my build script just runs ms build and runs some other tasks, however I want my compiled files to be put in a "build" directory, how can I tell msbuild where to put the compiled files?
Looking here:
http://msdn.microsoft.com/en-us/library/ms164311.aspx
it specifies that you can set msbuild to override the output dir setting in your project file, like so:
/properties:OutputDir=bin\Debug
Is this what you want?
you can put this in your project file (or in an imported project file if you want reuse), it will override both the path for the executable/dll and the path where the .obj files etc go.
<PropertyGroup>
<OutputPath>c:\bin</OutputPath>
<BaseIntermediateOutputPath>c:\temp\$(AssemblyName)</BaseIntermediateOutputPath>
</PropertyGroup>
If you are using the <msbuild> task from NAntContrib, then you can set the OutputDir property like this:
<msbuild project="path-to-sln-or-csproj-or-msbuild" target="Build">
<properties>
<property name="OutputDir" value="build-outdir-dir" />
</properties>
</msbuild>

Ant build scripts, antcall, dependencies, etc

I have a build script and as part of that script it copies a jar file to a directory, for ease lets call it the utils jar. the utils jar is built by another build script sitting in another directory. What im trying to do have my build script run the utils build script so that I can ensure the utils jar is up to date.
So I know I need to import the utils build file.
<import file="../utils/build/build.xml" />
Which doesn't work because the import task, unlike almost every other ant taks, doesn't run from basedir, it runs from the pwd. So to get around that I have this little ditty, which does successfully import the build file
<property name="baseDirUpOne" location=".." />
<import file="${baseDirUpOne}/utils/build/build.xml" />
So now that ive solved my import problem I need to call the task, well that should be easy right:
<antcall target="utils.package" />
note that in the above, utils is the project name of ../utils/build/build.xml
the problem I'm now running into is that ant call doesn't execute in ../utils/build so what I need, and cant find, is a runat property or something similar, essentially:
<antcall target="utils.package" runat="../utils/build" />
The reason I need this is that in my utils build file the step to select which code to copy to the jar is based on relative paths so as to avoid hardcoding paths in my ant file. Any ideas?
I've got something similar set up: I have a main Ant build.xml which calls a separate build.xml that takes care of building my tests. This is how I do it:
<target name="build-tests">
<subant target="build">
<fileset dir="${test.home}" includes="build.xml"/>
</subant>
</target>
The trick is to use subant instead of antcall. You don't have to import the other build file.
Try using the "ant" task instead of the "antcall" task, which runs the imported build directly instead of importing it into the current build file. It has a "dir" parameter:
the directory to use as a basedir
for the new Ant project. Defaults to
the current project's basedir, unless
inheritall has been set to false, in
which case it doesn't have a default
value. This will override the basedir
setting of the called project.
So you could do:
<ant antfile="${baseDirUpOne}/utils/build/build.xml" dir="../utils/build" />
or something like that.
You can pass params down to antcall using nested in the antcall block. So, you can pass the properties down that way (probably even basedir since properties are immutable).

Resources