问题描述
我已经实现了回显服务器客户端:连接到服务器,将字符串数据发送到服务器.服务器:打印输入的数据,将数据发送回客户端
I have implemented an echo serverClient : connects to server, sends string data to server.Server : prints incoming data, sends back data to client
我需要在cmd中使用ant来运行服务器和客户端.
I need to run both server and client using ant in cmd.
如何使相同的build.xml文件同时在服务器和客户端上运行.我可以将两个目标设置在同一文件中还是需要使用不同的build.xml文件.
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.
请在下面找到我正在使用的build.xml文件,该文件运行回显服务器.我还需要运行EchoClient.java.如何修改文件.
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"/>
推荐答案
在构建文件中使用两个目标.然后,您可以选择在启动ANT时运行哪个:
Use two targets in your build file. You can then choose which one to run when launching ANT:
ant run-server
and run-client
第一个目标
<target name="run-server" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
第二个目标
<target name="run-client" depends="jar">
<java classname="EchoClient" fork="true">
<classpath>
<pathelement location="${jar.dir}/${ant.project.name}.jar""/>
</classpath>
</java>
</target>
这篇关于如何修改build.xml以按此顺序运行多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!