从 ant 文件中引用 ant 脚本位置 [英] referencing ant script location from within ant file
问题描述
我有一个实用程序构建脚本,可以从构建服务器上的各种特定于项目的构建脚本中调用.一切正常,直到相对目录结构发生变化.即:
I have a utility build script that gets called from a variety of project-specific build scripts on a build server. Everything works fine, until the relative directory structure changes. That is:
trunk/
utilities/
imported.xml
some_resource_file
projectName/
importing.xml
工作正常,但有时我们需要:
works just fine, but sometimes we need:
trunk/
importing.xml
utilities/
imported.xml
some_resource_file
projectName/
问题是imported.xml
需要some_resource_file
并且当前通过引用../utilities/some_resource_file
来获取它.这显然适用于第一种情况,因为工作目录是 utilities
的同级.
The problem is that imported.xml
needs some_resource_file
and currently gets to it by referring to ../utilities/some_resource_file
. This obviously works in the first case because the working directory is a sibling of utilities
.
是否有一种简单的方法让 imported.xml
知道它在哪个目录中,相当于 bash 中的 dirname $0
?还是我必须以某种方式从导入脚本中注入它?
Is there a simple way for imported.xml
to know what directory it's in, something equivalent to dirname $0
in bash? Or do I have to do I have to somehow inject this from the importing script?
推荐答案
确保imported.xml 定义了具有name
属性的项目.然后,您可以通过 ant.file.name
属性使用该名称作为 ant 文件的绝对路径.
Make sure that imported.xml defines project with name
attribute. Then you can use that name for an absolute path to the ant file through ant.file.name
property.
我已将 IMPORTED 大写,因此您可以在代码中轻松看到它.
I have capitalized IMPORTED, so you can easily see it in the code.
<project
name="IMPORTED"
>
<dirname
property="IMPORTED.basedir"
file="${ant.file.IMPORTED}"
/>
<property name="myresource"
location="${IMPORTED.basedir}/some_resource_file"
/>
</project>
这篇关于从 ant 文件中引用 ant 脚本位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!