简体   繁体   中英

Running One Server and Two Clients using ANT

I am a newbie into ANT world. My Application is based on Client-Server architecture which is using "RMI" for communication.

I need to write an ANT build script which automatically compiles the whole code, starts the server and run two clients connected to that server.

Here's structure of my current build.xml file.(I am not sure what's wrong)

<?xml version="1.0" encoding="UTF-8"?>
<project default="runClientOne" name="MyFirstAntProject">   
    <target name="compile">     
        <javac srcdir="./src" destdir="classfiles" />       
    </target>       
    <target name="runServer" depends="compile" >
        <java classname="com.jain.RMIServer">
            <classpath path="classfiles" />
        </java>
    </target>       
    <target name="runClientOne" depends="runServer">            
        <java classname="com.jain.RMIClient" fork="true" taskname="A" >
            <classpath path="classfiles" />
            <arg value="localhost"/>
            <arg value="Sumit"/>
        </java>
        <java classname="com.jain.RMIClient" fork="true" taskname="B">
            <classpath path="classfiles" />
            <arg value="localhost"/>
            <arg value="Sushil"/>
        </java>
    </target>
</project>

Thanks Guys,

I have figured out that I will have to use the <parallel>My CODE </parallel> .

I stumbled upon this question when I was trying to accomplish a similar thing, here is how I achieved a target that starts running the server and client. (My answer expands on Sushil's and this SO answer )

Here is the case: I have a server, and when I start up I want 3 clients to connect to the server right away, all in a separate process.

The trick is to nest parallel and sequential in the build.xml targets individually .

The sleep call can be changed to wait on the process too.

   <target name="start-all" depends="build" 
                  description="Starts 1 Server and 2 clients ">
     <parallel>
       <sequential>
         <java classname="Server" fork="true">
           <classpath refid="master-classpath"/>
           <arg line="${port}"/>
         </java>
       </sequential>
       <sequential>
          <sleep milliseconds="500"/>
          <antcall target="start-client">
          <param name="server.address" value="localhost" />
          <param name="server.port" value="${port}"/>
          </antcall>
       </sequential>
     </parallel>
   </target>

This would start the server, and then the clients, alternatively, using <daemon> to start the server and then immediately launching the clients right after.

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