Ant: variable part in path as macro attribute

I have the following problem: How can I set the SERVERNAME variable on an element path

as a parameter to the macro ( myCompile

)?

<path id="myClasspath"  >
  <fileset>
    <include name="{??SERVERNAME??}/my.jar" />
  </fileset>
</path>

<macrodef name="myCompile">
  <attribute name="classPath" />
  <attribute name="server" />
  <sequential>
     <javac destdir="dest" classpathref="@{classPath}" srcdir="./src" />
  </sequential>
</macrodef>

<target name="Build_server1">
  <!-- as {??Servername??} in path should be used "server1" -->
  <myCompile classPath="myClasspath" server="server1"/>
</target>

<target name="Build_server2">
  <!-- as {??Servername??} in path should be used "server2"-->
  <myCompile classPath="myClasspath" server="server2"/>
</target>

      

EDIT . If <path>

moved to a macro, then the attributes of the macro can be used. But it is not possible to repeat using a specific path elsewhere. (See edit 2)

<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>

      

EDIT 2 can be reused path

after it has been defined in a macro.

+3


source to share


1 answer


I'm not an ANT expert, but I think the following will be helpful to start with:



<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>

      

+1


source







All Articles