2013-05-08 65 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

相关问题