Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Ant:路径中作为宏属性的变量部分_Java_Ant_Macros - Fatal编程技术网

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>


不幸的是,我遇到了一个错误:“Reference
myClasspath
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>