开发者

referencing ant script location from within ant file

开发者 https://www.devze.com 2022-12-10 18:39 出处:网络
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:

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/

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.

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?


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.

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>


Found the answer:

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

Check under resolving files against the imported file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号