3

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.

martin clayton
  • 76,436
  • 32
  • 213
  • 198
Sandro
  • 2,219
  • 4
  • 27
  • 41

3 Answers3

9

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.

martin clayton
  • 76,436
  • 32
  • 213
  • 198
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
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.

martin clayton
  • 76,436
  • 32
  • 213
  • 198
Arkaaito
  • 7,347
  • 3
  • 39
  • 56
  • I see, the only problem that I have with exec is that running java programs across OS is very different. I would need an exec for every os, no? – Sandro Jan 29 '10 at 00:31
3

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*.

martin clayton
  • 76,436
  • 32
  • 213
  • 198
  • Is there an OS independent solution? – Sandro Jan 29 '10 at 00:32
  • Using the java task with spawn is OS independent. If you want to spawn different executables then you are certainly heading into an OS specific world. But the exec task allows you to specify which OS's the task is ran for.. (run this only on windows, run this only on unix, etc) – Matt Jan 29 '10 at 01:38