Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find working directory from Ant

Tags:

java

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> 

but that doesn't work.

like image 918
JW. Avatar asked Oct 20 '09 18:10

JW.


People also ask

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.

How do I call ant target from command line?

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 Ant build XML?

Ant uses an xml file for its configuration. The default file name is build. xml . Ant builds are based on three blocks: tasks, targets and extension points. A task is a unit of work which should be performed and constitutes of small atomic steps, for example compile source code or create Javadoc.


2 Answers

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

<echo>${user.dir}</echo> 
like image 142
Asaph Avatar answered Sep 22 '22 23:09

Asaph


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

like image 34
java.is.for.desktop Avatar answered Sep 20 '22 23:09

java.is.for.desktop