从Ant文件中引用ant脚本位置 [英] referencing ant script location from within ant file

查看:169
本文介绍了从Ant文件中引用ant脚本位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被从各种构建服务器上的特定项目构建脚本称为效用构建脚本。一切工作正常,直到相对目录结构的变化。这就是:

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 ,目前参考<$ C $获取到它C> ../实用工具/ some_resource_file 。这显然​​作品在第一种情况下,因为工作目录是公用事业同级

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 一个简单的方法来知道它在什么目录,以目录名$ 1,0 的东西当量在bash?或做我必须做我必须以某种方式从进口脚本注入呢?

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定义项目,名称属性。然后,您可以通过使用该名称的蚂蚁文件的绝对路径 ant.file.name 属性。

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.

我都利用进口的,所以你可以很容易地看到它在code。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆