java - variable - Find working directory from Ant




print current directory in ant (2)

Is it possible to tell which directory the user ran Ant from?

For example, I might want to run only the unit tests in the current working directory, rather than all tests for the entire project.

I tried this:

<property environment="env" />
<echo>${env.CWD}</echo>

but that doesn't work.


${basedir} might also be useful.

In Netbeans under Linux, ${user.dir} seems always to equal ${user.home}, but ${basedir} gives me actual directory where ant is ran from (so it gives me the project dir).


The whole Properties object returned by System.getProperties() is exposed by Ant. Try this:

<echo>${user.dir}</echo>




ant