我正在尝试设置一个 antfile(位于目录 A 中的“antfile_A”)来调用另一个 antfile(位于目录 B 中的“antfile_B”)。
我的问题是,当我从 antfile_A 调用 antfile_B 时,所有文件操作似乎都与目录 A 相关。我可以将 antfile_b 中的路径硬编码为与目录 A 相关,但是我不能真正单独使用 antfile_B。
我试过在每个 antfile 的顶部设置 basedir(到“.”),但是“。” 当从 antfile_A 调用 antfile_B 时,似乎解析到目录 A。
有没有办法直接获取antfile所在的绝对目录?在python中,它会是这样的
os.path.abspath(os.path.dirname(__file__))
Run Code Online (Sandbox Code Playgroud)
其他人如何解决这个问题?(或者你真的不应该从另一个调用一个 antfile 吗?)请告诉我。谢谢!
小智 6
使用ant.file. 此示例打印构建文件的绝对路径:
<project name="MyProject" default="abspath" basedir=".">
<target name="abspath">
<echo message="${ant.file}"/>
</target>
</project>
Run Code Online (Sandbox Code Playgroud)
如果您尝试ant使用-d(debug output) 标志运行,您会发现在调用第一个目标之前设置的属性,因此可以在构建文件中使用。
当上面的构建文件使用-d标志运行时,这是从输出中获取的:
...
Setting ro project property: ant.file -> /Users/abc/xyz/build.xml
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Setting ro project property: ant.file.type -> file
Setting ro project property: ant.project.name -> MyProject
Setting ro project property: ant.project.default-target -> abspath
Setting ro project property: ant.file.MyProject -> /Users/abc/xyz/build.xml
Setting ro project property: ant.file.type.MyProject -> file
...
Run Code Online (Sandbox Code Playgroud)
为了完整起见,您可以通过创建一个变量来获取包含构建脚本的目录的路径,如下所示:
<dirname property="my.project.dir" file="${ant.file}"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6187 次 |
| 最近记录: |