【问题标题】:referencing ant script location from within ant file从 ant 文件中引用 ant 脚本位置
【发布时间】:2011-01-18 01:21:17
【问题描述】:

我有一个实用程序构建脚本,可以从构建服务器上的各种特定于项目的构建脚本中调用。一切正常,直到相对目录结构发生变化。那就是:

trunk/
    utilities/
        imported.xml
        some_resource_file
    projectName/
        importing.xml

工作得很好,但有时我们需要:

trunk/
    importing.xml
    utilities/
        imported.xml
        some_resource_file
    projectName/

问题是imported.xml 需要some_resource_file 并且目前通过引用../utilities/some_resource_file 得到它。这显然适用于第一种情况,因为工作目录是 utilities 的兄弟。

有没有一种简单的方法让imported.xml 知道它在哪个目录中,相当于bash 中的dirname $0?还是我必须以某种方式从导入脚本中注入它?

【问题讨论】:

    标签: java ant


    【解决方案1】:

    确保imported.xml 使用name 属性定义项目。然后,您可以通过ant.file.name 属性将该名称用作ant 文件的绝对路径。

    我已经大写了IMPORTED,所以你可以很容易地在代码中看到它。

    <project
      name="IMPORTED"
    >
      <dirname
        property="IMPORTED.basedir"
        file="${ant.file.IMPORTED}"
      />
      <property name="myresource"
        location="${IMPORTED.basedir}/some_resource_file"
      />
    </project>
    

    【讨论】:

    • 效果很好。我在手册中找到了答案,但只复制了这里的链接。也许这会帮助那些不方便浏览 ant 手册的人。
    【解决方案2】:

    找到答案:

    http://ant.apache.org/manual/Tasks/import.html

    根据导入的文件解析文件下检查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2012-03-28
      • 2010-12-27
      • 2016-06-12
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      相关资源
      最近更新 更多