How to modify build.xml to run multiple files in that order

一曲冷凌霜 提交于 2019-12-14 03:16:54

问题


I have implemented an echo server Client : connects to server, sends string data to server. Server : prints incoming data, sends back data to client

I need to run both server and client using ant in cmd.

How do I make the same build.xml file run both server and client. Can I set both targets in the same file or do I need to use different build.xml files.

Please find below, build.xml file that I am using, which runs the echo server. I need to run the EchoClient.java as well. How do I modify the file.

<property name="src.dir"     value="src"/>

<property name="build.dir"   value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir"     value="${build.dir}/jar"/>

<property name="main-class"  value="EchoServer"/>



<target name="clean">
    <delete dir="${build.dir}"/>
</target>

<target name="compile">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false"/>
</target>

<target name="jar" depends="compile">
    <mkdir dir="${jar.dir}"/>
    <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
        <manifest>
            <attribute name="Main-Class" value="${main-class}"/>
        </manifest>
    </jar>
</target>

<target name="run" depends="jar">
    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>

<target name="clean-build" depends="clean,jar"/>

<target name="main" depends="clean,run"/>


回答1:


Use two targets in your build file. You can then choose which one to run when launching ANT:

ant run-server
and run-client

First target

<target name="run-server" depends="jar">
    <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>

Second target

<target name="run-client" depends="jar">
    <java classname="EchoClient" fork="true">
      <classpath>
        <pathelement location="${jar.dir}/${ant.project.name}.jar""/>
      </classpath>
    </java>
</target>


来源:https://stackoverflow.com/questions/20297354/how-to-modify-build-xml-to-run-multiple-files-in-that-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!