Getting and using the parent directory through ANT

I have a directory structure and build.xml like this

/path-to-project/src/prj1 /path-to-project/src/prj2 /path-to-project/tests /path-to-project/tests/build.xml 

I need to get a way somehow

  /path-to-project/ 

in my build.xml file

My build.xml file is similar to this

 <project name="php-project-1" default="build" basedir="."> <property name="source" value="src"/> <target name="phploc" description="Generate phploc.csv"> <exec executable="phploc"> <arg value="--log-csv" /> <arg value="${basedir}/build/logs/phploc.csv" /> <arg path="${source}" /> </exec> </target> </project> 

Here, I somehow want to get the value of ${source} as /path-to-project/src/ , but I don't get it with ${parent.dir}

Is it possible to get this path in the build.xml file?

+4
source share
2 answers

You can use .. just like on the command line to go to the parent directory.

 <project name="php-project-1" default="build" basedir="."> <property name="root.dir" location=".."/> <property name="source" location="${root.dir}/src"/> ... </project> 

Update: Changed value to location in accordance with the martin answer you have to accept.

+9
source

You must use the location attribute, not value , to set the source property:

 <property name="source" location="src"/> 

Ant will then set the property to an absolute path for the given location. If the location looks like a relative path, the absolute path is calculated relative to the base. The property task has other attributes that you can use for further customization.

To get the parent directory on your server, you can also use:

 <property name="parent.dir" location=".." /> 

(at least on a unix machine not tested on windows.)

+7
source

All Articles