2013-05-08 55 views

回答

0

或者使用具有可執行的java.exe這樣的應用:

<apply executable="path/to/java.exe"> 
    <arg value="..."/> 
    <arg value="..."/> 
    ... 
    <fileset dir="..."/> 
    ... 
</apply> 

,或者使用一些AntAddon,提供了一個for循環,即Flaka,看到Wiki examples/Files + Directories
問:我編譯Java源代碼之後怎麼運行相應的類?
解決方案:遍歷包含java源文件集並使用replace函數調用相應的類文件。

<project xmlns:fl="antlib:it.haefelinger.flaka"> 

    <property name="srcroot" value="path/to/srcrootdir"/> 
    <property name="classroot" value="path/to/classrootdir"/> 

    <!-- seek all classes with main method --> 
    <fileset dir="${srcroot}" includes="**/*.java" id="mainclasses"> 
    <contains text="public static void main"/> 
    </fileset> 

    <!-- iterate over classes with main method and call 
     corresponding classfile --> 
    <fl:for var="file" in="split('${toString:mainclasses}', ';')"> 
    <fl:let> 
     ; strip the '.java' extension 
     file = replace(file, '', '.java') 
     ; replace fileseparator with '.' 
     ; when running on windows you have to use : 
     ; replace(file, '\.', '${file.separator}${file.separator}') 
     file = replace(file, '\.', '${file.separator}') 
     </fl:let> 
    <fl:echo> 
     starting => #{file} in ${classroot}.. 
    </fl:echo> 
    <java classname="#{file}"> 
     <classpath> 
     <!-- 
     when using a fileset you'll get a 
     java.util.zip.ZipException because you're 
     referencing not jarfiles but classfiles 
     therefore you've to use pathelement location 
     --> 
     <pathelement location="${classroot}"/> 
     </classpath> 
    </java> 
    </fl:for> 

</project> 
0

使用來自here<java>任務。但它不能將它自己應用於文件集。 Example

相關問題