Alex Rivera | Logout

How to set Ant properties based on variables in Eclipse?

Asked 2011-01-11T17:10:57.553
12

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:

  1. Works on different machines with different paths to the project root (i.e. in a team environment)
  2. Allows the ant build.xml file to be executed inside eclipse
  3. Allows the ant build.xml file to be executed outside of eclipse (i.e. from command line)
  4. Allows the build.properties file to exist in a directory other than the project root
Edit
Report

1 Answer

9

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.

answered 2011-01-11T17:45:38.543

Your Answer