ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nik Silver <antl...@pigsaw.org>
Subject [PATCH] Keeping Java processes running after exit
Date Fri, 07 Mar 2003 18:23:10 GMT
Hello

I have been frustrated by a change between Ant 1.4.1 and Ant 1.5,
and I offer here a patch. First I describe the problem, then my
solution.

I had previously used Ant to start my Tomcat engine ("ant start-server").
This was by using a Java task with fork="true". When Ant exited my
server was up and running. This kind of task is closely related to
my testing process, which would build servlets, restart the server
and run my tests. It follows naturally that I should want to use Ant
for more general task of starting the server. Unfortunately with the move
to 1.5 when the Ant VM terminates it also terminates its child processes,
so this functionality has gone. This has frustrated me.

My solution has been to add a new option to the Java task. It is called
"destroy". I have also added to the manual. The entry for the "destroy"
option reads like this:

    If "true", will destroy the forked process once the Ant VM exits.
    This is the default setting. However, you may wish to set this to
    "false" if, for example, your forked Java process starts a Web server
    which you want to continue running after Ant completes. (Ignored if fork
    is disabled.)

You can see from this that the change is backwards compatible; existing
scripts will not break with it. The work also means I added a field to the
Execute class, set using a new setDestroy() method. The Java class simply
sets the method in the Execute class. The attached diff files are
based on 1.5.2beta1.

Unfortunately I've not been able to write automatic tests for this since
I cannot get the existing ones working ("ant test" fails).

As an aside, I'd like to be able to fork an Exec task to, say, start
a database from Ant using a shell script. But that's another matter
for another day. Hope this is okay and a kindly committer can include
this in a future release.

Nik

-- 
http://www.workkitchen.org
Problems at work? Join the discussion forum

Mime
View raw message