R
R
raner1342017-09-24 15:31:49
Java
raner134, 2017-09-24 15:31:49

When compiling and running via Ant, how can I make two classes run sequentially?

There is a client-server application on sockets. How to make it so that when building and running through ant, the server is called first, and after it the client?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2017-09-25
@raner134

<target name="run" description="Run jars">
    <java jar="path/to/server.jar" fork="true"/>

    <waitfor maxwait="5" maxwaitunit="seconds" timeoutproperty="failtimeout">
        <socket server="localhost" port="9999"/>
    </waitfor>
    <if>
         <not>
              <equals arg1="${failtimeout}" arg2="true"/>
         </not>
              <then>
                  <java jar="path/to/client.jar" fork="true"/>
              </then>
    </if>
</target>

As I understand it, the problem is that the server and client start at the same time, and the client crashes. cannot connect to the server. You can get around this with the waitfor task .
Those. we start the server, wait a maximum of 5 seconds until the localhost server responds on port 9999, then we start the client if we managed to reach the server in the given time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question