Let's say I have a file-system that looks a little something like this:
- C:\stuff\build.xml
- C:\stuff\myfolder\library1.jar
- C:\stuff\myfolder\library2.jar
Inside build.xml, I want to define a path that looks like this:
<path id="some.id">
<fileset dir="myfolder">
开发者_JS百科 <include name="**/*.jar"/>
</fileset>
</path>
Normally that works fine. However, I am calling my own custom Ant Task that will inherit any references (including the path "some.id") and that custom Ant Task will call a build.xml that lives in a different basedir. Therefore, the "dir" attribute in the fileset is no longer valid.
Is there a way to define a "dir" such that it remains valid no matter where the second build.xml lives?
I essentially want to do something like this:
<fileset dir="${expand.current.directory}/myfolder">
So when I call the second build.xml it will understand that the "dir" attribute is the location of:
<fileset dir="c:\stuff\myfolder">
Edit: Furthermore, I want a solution that allows me to copy the "stuff" project from one machine to another without requiring a change to the build. For example, if the "stuff" project is on the C: drive and I copy the project over to a D: drive on another machine, I want the build to continue to work without me having to go into the build and change the letter C to the letter D.
I think you're after the ${user.dir}
property - which is the current working directory.
All java System.properties are available as ant properties.
Option 1: You can define an Ant property.
At the beggining of the file you can define this property:
<property name="myproject.root.path" location="C:/stuff/"/>
And then, use it:
<fileset dir="${myproject.root.path}/myfolder">
Option 2: You can also define it at an external build.properties file, located at the same folder in wich the build.xml file is.
File C:\stuff\build.properties
myproject.root.path=C:/stuff/
And, to make use of this file you have to add this line at the Ant XML file (recommended before the tasks definition):
<property file="build.properties"/>
Once you have this file included, you can use the properties along the project, the same way as seen at option 1:
<fileset dir="${myproject.root.path}/myfolder">
You can add more than one properties file.
Note that paths are defined using slashes, and not back-slashes.
精彩评论