I have a client and a server that I’m building with Ant. The client relies on the server being built first before it can build. I have all of the required libraries except the server ear file bundled in the client.
I created 3 ant files build.xml, build-client.xml, and build-server.xml. (Click on any of the file names to see them) The files build-client.xml and build-server.xml are included in build.xml so that it can run targets from them.
The problem I’m having is that the basedir variable changes from build file to build file. So if I run targets in build-client.xml from build.xml the basedir variable is relative to build.xml.
How do I change the basedir variable multiple times within an Ant script?
Also, looking at these build files, do you see a better way of doing what I’m trying to do? Right now I’m thinking that I have to have both the client war and server ear in the same location before I can make the final bundled ear. My idea about this may be flawed though because these scripts seem unnecessarily complex.
The ant documentation for
<import>task gives you information about how to accomplish this.Resolving files against the imported file
Suppose your main build file called importing.xml imports a build file imported.xml, located anywhere on the file system, and imported.xml reads a set of properties from imported.properties:
This snippet however will resolve imported.properties against the
basedirof importing.xml, because thebasedirof imported.xml is ignored by Ant. The right way to use imported.properties is:As explained above
${ant.file.imported}stores the path of the build script, that defines the project called imported, (in short it stores the path to imported.xml) and<dirname>takes its directory. This technique also allows imported.xml to be used as a standalone file (without being imported in other project).Basically, you can’t really use the
${basedir}variable, nor thebasedir="./../GrahamsProjClient"attribute in your project tag, but instead you can construct it:You can do the same for the build-server.xml, the only thing to watch for is that the project name is featured in the
${ant.file.[project name]}file attribute for<dirname />.