Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

referencing ant script location from within ant file

Tags:

java

ant

I have a utility build script that gets called from a variety of project-specific build scripts on a build server. Everything works fine, until the relative directory structure changes. That is:

trunk/
    utilities/
        imported.xml
        some_resource_file
    projectName/
        importing.xml

works just fine, but sometimes we need:

trunk/
    importing.xml
    utilities/
        imported.xml
        some_resource_file
    projectName/

The problem is that imported.xml needs some_resource_file and currently gets to it by referring to ../utilities/some_resource_file. This obviously works in the first case because the working directory is a sibling of utilities.

Is there a simple way for imported.xml to know what directory it's in, something equivalent to dirname $0 in bash? Or do I have to do I have to somehow inject this from the importing script?

like image 616
David Berger Avatar asked Nov 04 '09 21:11

David Berger


People also ask

How do I run a specific target in Ant?

To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.

What is Basedir in Ant?

The 'basedir' is the base directory from which any relative directories used within the Ant build file are referenced from. If this is omitted the parent directory of the build file will be used.

What is Refid in Ant?

Ant expands this into an absolute filename internally. path (all, String, *) A list of file and pathnames, delimited by ; or : . refid (all, Reference, *) A reference to a path defined elsewhere in the current buildfile.

What is PathElement in Ant?

Path: This object represents a path as used by CLASSPATH or PATH environment variable. A path might also be described as a collection of unique filesystem resources. and PathElement: Helper class, holds the nested <pathelement> values.


1 Answers

Make sure that imported.xml defines project with name attribute. Then you can use that name for an absolute path to the ant file through ant.file.name property.

I have capitalized IMPORTED, so you can easily see it in the code.

<project
  name="IMPORTED"
>
  <dirname
    property="IMPORTED.basedir"
    file="${ant.file.IMPORTED}"
  />
  <property name="myresource"
    location="${IMPORTED.basedir}/some_resource_file"
  />
</project>
like image 72
Alexander Pogrebnyak Avatar answered Oct 04 '22 16:10

Alexander Pogrebnyak