Reputation: 17895
I have a common problem and there are probably countless ways to solve it. I'm looking for an elegant, simple solution to this typical scenario:
I have a project in Eclipse with an Ant build file (build.xml) the build file uses a property file (build.properties). In that property file, I want to set a property that points to the root directory of the eclipse project such as:
project.root = /path/to/eclipse/workspace/projectName
or preferably:
project.root = ${path.to.eclipse.workspace}/projectName
How do I do this in such a way that:
Upvotes: 12
Views: 39068
Reputation: 76
You can set eclipse relative properties for your ANT Build from eclipse
Go to your ANT Builder properties and in arguments section you can set properties using -D as below
-Dworkspace="${workspace_loc}" -Dproject_dir="${project_loc}"
(here workspace_loc and project_loc are eclipse variables). These properties can be accessed in your ANT build script like regular properties, for example:
<echo message="${workspace}" />
<echo message="${project_dir}" />
Upvotes: 1
Reputation: 10377
if you need more than the trivial basedir stuff =
Ant4Eclipse - a bunch of ant tasks for access to eclipse configurations from within ant -
may help you. Just use it as is or grep the code and pick the relevant parts..
Upvotes: 3
Reputation: 31
For my project archieve.
ProjectName <dir>
|_ ant <dir>
|_ ant.xml
Your case can just simply change the ant xml file, the <project default="main" basedir="../"/>
Then I can get the project root using variable of
e.g. <echo message= "Project Root: ${basedir}" />
Upvotes: 3
Reputation: 17895
I think what I'm looking for is to add the following to the build.properties file:
project.root = ${basedir}
alternatively, I can just use the basedir property whenever project.root is needed.
I happened to be looking at the source code for ivy.properties and I saw the basedir property being used. I just tested and verified that this property works on different machines both from inside eclipse and from the command line as well as when making a call to ant from a different directory such as:
ant -f /path/to/eclipse/workspace/projectName/build.xml
When I get a minute, I will verify that this also works when importing the property file in different locations (such as inside src/main/resources/config/ivy/ivysettings.xml).
Upvotes: 7
Reputation: 29139
See Window -> Preferences -> Ant -> Runtime -> Properties to define custom ant properties that should be available to any ant script invoked from Eclipse. The simply set the same property manually when invoking script from command-line.
Your build.properties file can exist wherever you like. Use normal Ant facilities to import it into your script.
Upvotes: 9