Java Ant:路径中作为宏属性的变量部分
我有以下问题,如何将Java Ant:路径中作为宏属性的变量部分,java,ant,macros,Java,Ant,Macros,我有以下问题,如何将path元素中的变量“SERVERNAME”设置为宏(myCompile)的参数 编辑:如果将移动到宏,则可以使用宏的属性。但不可能在其他地方重用定义的路径。(见编辑2) 编辑2在宏中定义路径后,可以重用路径。我不是蚂蚁专家,但我认为以下内容将为您提供一个良好的开端: <macrodef name="myCompile"> <attribute name="classPath" /> <sequential> &l
path
元素中的变量“SERVERNAME”设置为宏(myCompile
)的参数
编辑:如果将
移动到宏,则可以使用宏的属性。但不可能在其他地方重用定义的路径。(见编辑2)
编辑2在宏中定义路径后,可以重用路径。我不是蚂蚁专家,但我认为以下内容将为您提供一个良好的开端:
<macrodef name="myCompile">
<attribute name="classPath" />
<sequential>
<javac destdir="dest" classpathref="@{classPath}" srcdir="./src" />
</sequential>
</macrodef>
<target name="Build_server1">
<property name="server" value="server1"/>
<antcall target="setMyClassPath"/>
</target>
<target name="Build_server2">
<property name="server" value="server2"/>
<antcall target="setMyClassPath"/>
</target>
<target name="setMyClasspath">
<path id="myClasspath">
<fileset>
<include name="${server}/my.jar" />
</fileset>
</path>
<myCompile classPath="myClasspath"/> << Add here and removed from above
</target>
不幸的是,我遇到了一个错误:“ReferencemyClasspath
notfound”。如果我将path
移动到macrodef
本身,则编译成功。我想请参见对问题的编辑。同样的行为也适用于你的答案。
<macrodef name="myCompile">
<attribute name="classPath" />
<attribute name="server" />
<sequential>
<path id="myClasspath" >
<fileset>
<include name="@{server}/my.jar" />
</fileset>
</path>
<javac destdir="dest" classpathref="@{classPath}" srcdir="./src" />
</sequential>
</macrodef>
<macrodef name="myCompile">
<attribute name="classPath" />
<sequential>
<javac destdir="dest" classpathref="@{classPath}" srcdir="./src" />
</sequential>
</macrodef>
<target name="Build_server1">
<property name="server" value="server1"/>
<antcall target="setMyClassPath"/>
</target>
<target name="Build_server2">
<property name="server" value="server2"/>
<antcall target="setMyClassPath"/>
</target>
<target name="setMyClasspath">
<path id="myClasspath">
<fileset>
<include name="${server}/my.jar" />
</fileset>
</path>
<myCompile classPath="myClasspath"/> << Add here and removed from above
</target>