Question

I would like to start Server and the ProxyServer class simultaneously, using Ant tag, is it possible to run the wo classes?

Here is the code I tried but Ant only starts the Server class and does not do anything there after, not sure if there is away in ant to achieve this.

Appreciate your help.

<target name="pxyServer" depends="server">
    <echo>Executing Target - Run ProxyServer</echo>
    <java classname="pxy.ProxyServer">
        <classpath path="staging" />
    </java>
</target>

<target name="server">
    <echo>Executing Target - RunServer</echo>
    <java classname="pxy.Server">
        <classpath path="staging" />
    </java>
</target>
Was it helpful?

Solution

Your targets are executed sequentially, and since the first one keeps running, the second one never gets the chance to start.

For parallel execution, you can use ant's "parallel" task: http://ant.apache.org/manual/Tasks/parallel.html

Your modified script should probably look something like this:

<target name="startServerAndProxy">
    <echo>Running server and proxy...</echo>
    <parallel>
        <java classname="pxy.Server">
            <classpath path="staging" />
        </java>
        <java classname="pxy.ProxyServer">
            <classpath path="staging" />
        </java>
    </parallel>
</target>

(Of course, if you're trying to start some third application in parallel, a client for example, then you should also include that one in the "parallel".)

UPDATE:

To start the server and the proxy each in its own console, I don't know if it can be done with the "java" Ant task, but I just tested that it can be done with "exec":

<target name="doit">
    <parallel>
        <exec executable="cmd" dir="staging">
            <arg line="/k start java.exe pxy.Server"/>
        </exec>
        <exec executable="cmd" dir="staging">
            <arg line="/k start java.exe pxy.ProxyServer"/>
        </exec>
    </parallel>
</target>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top