2016-11-02 7 views
0
개미

에서 의 각 에 대한 : 전화는 다음과 같이 나는 <code>path</code>이

<path refid="myjarlocation"/> 

이 지금은이 경로를 통해하고 경로에 존재하는 각 값에 대해 반복 할 내가 macrodef를 호출 할 이 값을 marcodef 내부에서 사용할 속성 중 하나로 사용합니다. 다음과 같이

대상의 경우 우리는 그것을 쉽게 할 수 있습니다 내가 여러 매개 변수를 전달해야하기 때문에

<foreach target="mytarget" param="jarloc"> 
    <path refid="myjarlocation"/> 
</foreach> 

나는 각각 사용할 수 없습니다, 그래서 나는 macrodef을 사용하고 있습니다. 따라서 경로를 반복하고 대상 대신 macrodef를 호출하는 방법에 대해 질문하십시오.

+0

'이 경로를 통해 반복'이란 무엇을 의미합니까? – Rao

+0

이 내 경로 과 같을 것이다 어떻게 <경로 ID = "myjarlocation"> 반복함으로써 , "1.jar", "2.jar"등과 같은 각 위치를 검색해야합니다. – user2713255

답변

2

ant-contrib의 for 작업을 사용하여 경로를 반복하고 path 요소를 macrodef에 전달하여 유사한 작업을했습니다.

먼저 프로젝트에서 개미의 contrib를 얻을 - http://ant-contrib.sourceforge.net/

다음, 그러나 당신이 당신의 경로 요소를 가지고 몇 가지 속성을 포함하려는 개미 빌드에 macrodef 정의를 참조하십시오. 예 :

<for param="path.element"> 
    <fileset dir="${jars.dir}"> 
     <include name="*.jar"/> 
    </fileset> 
    <sequential> 
     <awesome-macro path-to-deal-with="@{path.element}" unrelated-attribute="whatever"/> 
    </sequential> 
</for> 

주 루프의 내부 ${path.element}에 반대 @{path.element}의 사용이 참조하는 그런 다음

<macrodef name="awesome-macro"> 
    <attribute name="path-to-deal-with"/> 
    <attribute name="unrelated-attribute"/> 
    <sequential> 
     ... 
    </sequential> 
</macrodef> 

는 pathelements로의 경로를 반복하고 매크로를 호출 할 for 작업을 사용하여 루핑 매개 변수!

+0

언급 한 것과 같은 접근 방식을 사용해 주셔서 감사합니다. – user2713255