问题
I am currently developing a "debugger" java application that uses JDI to connect to an already running "target" java application. Is there any way to have Ant launch my target application then launch my "debugger" afterwards, while the first application is still running?
Yes I know that I can develop the JDI app to launch the target program, but that is not what I want right now.
回答1:
You can spawn two java programs from within an Ant parallel task.
<parallel>
<sequential>
<java fork="true" classname="prog1 .... >
</sequential>
<sequential>
<sleep seconds="30"/>
<java fork="true" classname="prog2.... >
</sequential>
</parallel>
The sleep task in the second thread could be replace by a waitfor condition.
回答2:
You can certainly spawn processes from Ant. Here's a simple example:
<target name="sleeper">
<exec executable="sleep" spawn="yes">
<arg value="100" />
</exec>
</target>
If you run this task* you'll see Ant run to completion, but a ps
will show the sleep persists.
The java task also supports spawn
.
**the example assumes a UNIX variant OS as it uses the sleep command*.
回答3:
Look at the doc for Ant's <exec>
directive - you should be able to add a call to the target application with <exec>
that will amp off by using the "spawn" parameter.
Edit: sorry, "amp off" is slang for running a process in the background, which allows Ant to continue working while that process runs.
来源:https://stackoverflow.com/questions/2158937/can-ant-launch-two-java-applications-concurrently