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:
The <property> task is used to set the Ant properties. The property value is immutable, once the value is set you cannot change it. To set a property to a specific value you use Name/value assignment. To set a property to a location you use Name/location assignment.
Ant Properties are set once and then can never be overridden. That's why setting any property on the command line via a -Dproperty=value will always override anything you've set in the file; the property is set and then nothing can override it. This way: Anything set at the command line takes precedence over build.
The home directory for Ant library files - typically ANT_HOME/lib folder. Ant also makes the system properties (Example: file. separator) available to the build file. In addition to the above, the user can define additional properties using the property element.
Tip. You also can start an Ant build by highlighting the project in the Package Explorer and selecting Run→ External Tools→ Run As→ Ant Build. If you want to select the targets to run, you also can select Run→ External Tools→ External Tools→ Targets, select the targets you want to run, and click Run.
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}" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With