我正在研究 ant 的工作原理,但我对此有一些疑问。我有一个以这种方式开始的 ant xml 脚本定义文件:
<?xml version="1.0"?>
<project name="Peacock Engine" default="default"> <!-- "default" is the default target -->
<tstamp />
<!-- ============================================ -->
<!-- Load build properties -->
<!-- ============================================ -->
<property name="project.buildfile" value="build.num" />
<property file="${project.buildfile}" />
<property file="info.properties" />
<!-- ============================================ -->
<!-- Specify the classpath -->
<!-- ============================================ -->
<path id="project.classpath">
<fileset dir="${project.libdir}">
<include name="${project.libs}" />
</fileset>
</path>
<!-- ============================================ -->
<!-- The default target -->
<!-- ============================================ -->
<target name="default" depends="jar"/>
现在帮我分析一下:
1) project 标签是根目标,我用它来指定项目属性。
2) :这行代码到底做什么?
3)然后我有这些行:
<property name="project.buildfile" value="build.num" />
<property file="${project.buildfile}" />
<property file="info.properties" />
具体做什么?我认为第一行创建类似于名为 project.buildfile 的变量,并将名为 build.num 的文件的内容加载到其中 关于以下两行,我对它们的作用知之甚少......你能帮助我吗?
4)然后在 ant 脚本中我找到这些行:
<!-- ============================================ -->
<!-- Specify the classpath -->
<!-- ============================================ -->
<path id="project.classpath">
<fileset dir="${project.libdir}">
<include name="${project.libs}" />
</fileset>
</path>
我尝试在网络上搜索,但我完全不知道这一部分
5) Finnslly 我有这个部分,它是默认目标的定义,它是当我启动 ant 脚本而不指定特定任务(特定目标)时执行的默认操作:
<!-- ============================================ -->
<!-- The default target -->
<!-- ============================================ -->
<target name="default" depends="jar"/>
我对此并不完全确定,但我认为通过这一行,我想说的是 ant 脚本的默认行为是编译程序,并且编译后的程序将其放入 Jar 文件中。
有人可以帮助我更好地理解这个脚本代码吗?
Tnx
安德里亚
最佳答案
1) 和 2) 这会将项目名称设置为“Peacock Engine”,并将默认任务设置为名为“default”的任务(参见 5))。如果您调用 Ant 而不提供特定任务,将执行默认任务:
<project name="Peacock Engine" default="default">
3) <property name="project.buildfile" value="build.num" />
创建一个属性,您可以使用 ${project.buildfile}
在 Ant 文件中的任何位置访问该属性。 。该属性的值为 build.num
<property file="${project.buildfile}" />
利用上面定义的属性。它基本上加载文件“build.num”并使该文件中定义的所有属性可供进一步使用。属性(property)文件如何运作? Have a look at the ant documentation of the property file task .
<property file="info.properties" />
加载另一个名为“info.properties”的属性文件,并使该文件中的所有属性可供 Ant 使用。
4)
<path id="project.classpath">
<fileset dir="${project.libdir}">
<include name="${project.libs}" />
</fileset>
</path>
这个标签定义了一个类路径。 path
标签包含一个文件集。该文件集包括 ${project.libdir}
中的所有库包括名称 ${project.libs}
。两者都是可能通过包含上面的属性文件来定义的变量。
实际上,此标记为您提供了一组库,可以通过引用其 id ( project.classpath
) 将其包含在构建文件中的任何位置。
5) <target name="default" depends="jar"/>
参见 1)。当未提供目标时,项目标记会引用此目标作为默认目标。该目标有另一个目标所依赖。 “depends”中指定的目标将在“default”之前执行。同样,如果“jar”有另一个依赖的目标,则该目标将首先执行,依此类推。这是一个“调用图”。请参阅documentation on targets了解更多相关信息。
您可能想查看 writing a simple build file 的 Ant 文档作为进一步熟悉 Ant 的起点。
关于java - 关于 ant 脚本这一部分的一些澄清?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19186030/