开发者

Find working directory from Ant

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>开发者_JAVA百科

but that doesn't work.


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

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


${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).


Unless you're using Windows, this will give you the current working directory:

<exec executable="sh" outputproperty="my.cwd"><arg line="-c pwd"/></exec>


and under windows

<exec executable="cmd" outputproperty="my.cwd"><arg line="/C echo %cd%"/></exec>

see also Using ant to detect os and set property

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜