ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Burton <>
Subject Re: antRunAsync and getting a background process to run indefinitely
Date Thu, 17 Apr 2003 20:25:44 GMT
Hello Melissa,

Melissa Hao wrote:
> Hi Bill,
> I am using Solaris 5.8 and csh.  The bgtest (ant exec_output) appears to work.
> I'm not sure if my setup is correct... let me describe my setup to you and you can tell
me if I'm invoking correctly.

Your setup looks correct.  The fact that you can successfully run the 
bgtest script but not your script is puzzling.  I'm wondering if 
  csh isn't sending some signal to all child processes when Ant exits 
which causes the java process to exit.

As another person pointed out, maybe you should try modifying the script 
and adding a "nohup" in front of the java command.

I tried to reproduce the problem but could not.  Ran Ant from csh with a 
java class that did a Thread.sleep(5000).  It always finished 
successfully after Ant had already finished.  When Ant finished running, 
I could run "ps" a few times and see the java process was still active.


> Here's the relevant part of my build.xml:
>     <property name="antRunAsync" value="/home/mhao/packages/antRunAsync/bin/antRunAsync"/>
>     <exec executable="${antRunAsync}" dir="${j2ee.home}" vmlauncher="false" failonerror="true">
>       <env key="ANTRUN_OUTPUT" value="oc4j2.log"/>
>       <env key="ANTRUN_NOHUP" value="true" />
>       <arg line=" start"/>
>     </exec>
> is a shell script that does many things.  In the middle of the script, it starts
up a java process:
>     ${JAVA_HOME}/bin/java -server -Xmx256m -jar ${J2EE_HOME}/oc4j.jar > ${J2EE_HOME}/oc4j.log
2>&1 &
> I would like the following two conditions to be met:
> - After processing the antRunAsync exec task, ant does not wait for the java process
to complete before going to the next task.  (This condition is currently being met.)
> - The java process continues after the ant process finishes.  (This condition is not
currently being met.)
> Am I setting up things correctly?
> thanks
> Melissa
> Bill Burton wrote:
>>Melissa Hao wrote:
>>>I'm having trouble getting the antRunAsync workaround to work exactly the way
I want.
>>>I use antRunAsync to run a shell script called  The shell script is started
asynchronously, which is great.  The shell script spawns a java process in the background
(eg, "java &").  I would like this java process to continue running after the
ant process completes.  Currently, the java process stops when the ant process stops.  Is
there any way to get the java process to run indefinitely?
>>I'm a little puzzled as to why this would be happening.  First, your
>> script would already be run in the background by the antRunAsync
>>script.  If the only thing (or the last thing) your script does is to
>>start "java" in the background, the "&" isn't necessary.  Only
>>if you want to start another process without waiting for that to
>>complete would you need to put your java command in the background.
>>Can you run the bgtest script and build file included in the archive to
>>see if you have the same problem?
>>Although this shouldn't be necessary, you could try redirecting all the
>>standard file descriptors, i.e.
>>     java </dev/null > 2>&1 &
>>This is what antRunAsync does if you specify
>>     <env key="ANTRUN_OUTPUT" value="some-output-file" />
>>to <exec> so it shouldn't be necessary.
>>What OS are you running on and what shell are you using?  Before posting
>>antRunAsync, the only UNIX OS I'd tested on was Solaris 2.8.  But in
>>theory, it should work the same way on all other UNIX OS's.

View raw message