简体   繁体   中英

run target in ant that depends on jar

I have a jar target in ant that makes a jar out of two classes that I have. Then, I want to run this jar in another target that depends on the jar target. Would there be an easy way to do this in ant? I have my compile and jar targets pasted below.

<project>
    <target name="compile">
        <mkdir dir="build/classes"/>
        <javac includeantruntime="false" srcdir="." destdir="build/classes"/>
    </target>

    <target name="jar">
        <mkdir dir="build/jar"/>
        <jar destfile="build/jar/KnightsTour.jar" basedir="build/classes">
        <manifest>
                <attribute name="Main-Class" value="PlayTour"/>
            </manifest>
                </jar>
    </target>
</project

To run a Java application, use the java task (see https://ant.apache.org/manual/Tasks/java.html for its documentation). An example from the docs:

<java jar="dist/test.jar" fork="true" failonerror="true" maxmemory="128m">
     <arg value="arg1"/>
     <arg value="arg2"/>
     <classpath>
       <pathelement location="dist/test.jar"/>
       <pathelement path="${java.class.path}"/>
     </classpath>
</java>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM