从ant文件中引用ant脚本位置

mfuanj7w  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(382)

我有一个实用工具构建脚本,可以从构建服务器上的各种特定于项目的构建脚本调用它。在相对目录结构改变之前,一切正常。即:

  1. trunk/
  2. utilities/
  3. imported.xml
  4. some_resource_file
  5. projectName/
  6. importing.xml

工作正常,但有时我们需要:

  1. trunk/
  2. importing.xml
  3. utilities/
  4. imported.xml
  5. some_resource_file
  6. projectName/

问题是 imported.xml 需要 some_resource_file 现在通过引用 ../utilities/some_resource_file . 这显然在第一种情况下有效,因为工作目录是 utilities .
有没有一个简单的方法 imported.xml 知道它在哪个目录下,相当于 dirname $0 在bash?或者我必须从导入脚本中注入这个吗?

ss2ws0br

ss2ws0br1#

确保imported.xml使用 name 属性。然后可以使用该名称作为ant文件的绝对路径,通过 ant.file.name 财产。
我已经把imported大写了,所以你可以很容易地在代码中看到它。

  1. <project
  2. name="IMPORTED"
  3. >
  4. <dirname
  5. property="IMPORTED.basedir"
  6. file="${ant.file.IMPORTED}"
  7. />
  8. <property name="myresource"
  9. location="${IMPORTED.basedir}/some_resource_file"
  10. />
  11. </project>
x4shl7ld

x4shl7ld2#

找到了答案:
http://ant.apache.org/manual/tasks/import.html
在“解析文件”下检查导入的文件。

相关问题