Grokbase Groups Ant user October 2007
FAQ

[Ant-user] <exec> called from a nested Ant session started with <java> - not terminating?

Keith Hatton
Oct 10, 2007 at 3:27 pm
Hi,

Versions: Ant 1.6.2 and 1.6.5, Java 1.5.0_05.

I have an Ant script that needs to call an Ant target with a different
environment (specifically with a different -lib setting) so I use <java>
to run this in a separate process as follows (the -lib is removed from
the arg sections here because the problem occurs even without it):

<java failonerror="true" fork="true"
classname="org.apache.tools.ant.launch.Launcher">
<env key="PATH" path="${java.library.path}"/>
<jvmarg value="-Dant.home=${ant.home}"/>
<arg value="-f"/>
<arg value="start_weblogic.xml"/>
<!-- -lib setting omitted -->
<classpath>
<pathelement path="${ant.home}/lib/ant-launcher.jar"/>
</classpath>
</java>
<echo>java has terminated</echo>


Now, the start_weblogic.xml build script runs another process with an
<exec> task with spawn="true", so that it should outlive the Ant script.
Here's the target:

<target name="wls-start-server">
<echo message="Start Weblogic Application Server"/>
<exec spawn="true" dir="${wls-domain-dir}" executable="cmd.exe"
os="Windows 2000,Windows 2003,Windows XP">
<arg line="/c startWebLogic.cmd"/>
</exec>

<waitfor maxwait="5" maxwaitunit="minute" checkevery="20000"
checkeveryunit="millisecond">
<http url="http://localhost:7001/console"/>
</waitfor>
<echo>WLS has started</echo>
</target>


Now, if I run start_weblogic.xml directly from the command line, with
the appropriate -lib settings etc., all is well, the script runs and
starts the server, leaving it running after the script has completed.

However, if I call the start_weblogic.xml script indirectly, from my
other script using the <java> task, it starts the server, I see the
<echo> message "WLS has started", and the BUILD SUCCESSFUL message.
However, the <java> task does not appear to terminate until the other
process (started with spawn="true" from a forked JVM) has been
terminated. Only then do I see the <echo> message "java has terminated"
from the first fragment. It appears that the nested Ant script has
completed, but the outer <java> task doesn't shut down. Interestingly,
the extra java.exe for the nested Ant script disappears from the Windows
Task Manager at the same time as the BUILD SUCCESSFUL message, so it
seems that the outer Ant script running the <java> task hasn't detected
this somehow.

Incidentally, the behaviour is identical if I use the <forget> task from
Ant-Contrib instead of the spawn="true" attribute.

Can anyone suggest what is going wrong here?

Thanks,
Keith


Axiom Systems Limited is a limited company registered in England and
Wales. Registered number: 2358771. Registered office: One Forbury
Square, The Forbury, Reading, Berks RG1 3EB

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
reply

Search Discussions

1 response

  • Martin Gainty at Oct 10, 2007 at 6:19 pm
    Hi keith-
    pure speculation but what if your start_weblogic.xml uses start /B (instead of cmd.exe /C)..
    Anyone?Martin--______________________________________________Disclaimer and confidentiality noteEverything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.> > Hi,> > Versions: Ant 1.6.2 and 1.6.5, Java 1.5.0_05.> > I have an Ant script that needs to call an Ant target with a different> environment (specifically with a different -lib setting) so I use <java>> to run this in a separate process as follows (the -lib is removed from> the arg sections here because the problem occurs even without it):> > <java failonerror="true" fork="true"> classname="org.apache.tools.ant.launch.Launcher">> <env key="PATH" path="${java.library.path}"/>> <jvmarg value="-Dant.home=${ant.home}"/>> <arg value="-f"/>> <arg value="start_weblogic.xml"/>> <!-- -lib setting omitted -->> <classpath>> <pathelement path="${ant.home}/lib/ant-launcher.jar"/>> </classpath>> </java>> <echo>java has terminated</echo>> > > Now, the start_weblogic.xml build script runs another process with an> <exec> task with spawn="true", so that it should outlive the Ant script.> Here's the target:> > <target name="wls-start-server"> > <echo message="Start Weblogic Application Server"/>> <exec spawn="true" dir="${wls-domain-dir}" executable="cmd.exe"> os="Windows 2000,Windows 2003,Windows XP">> <arg line="/c startWebLogic.cmd"/>> </exec>> > <waitfor maxwait="5" maxwaitunit="minute" checkevery="20000"> checkeveryunit="millisecond">> <http url="http://localhost:7001/console"/>> </waitfor>> <echo>WLS has started</echo>> </target>> > > Now, if I run start_weblogic.xml directly from the command line, with> the appropriate -lib settings etc., all is well, the script runs and> starts the server, leaving it running after the script has completed.> > However, if I call the start_weblogic.xml script indirectly, from my> other script using the <java> task, it starts the server, I see the> <echo> message "WLS has started", and the BUILD SUCCESSFUL message.> However, the <java> task does not appear to terminate until the other> process (started with spawn="true" from a forked JVM) has been> terminated. Only then do I see the <echo> message "java has terminated"> from the first fragment. It appears that the nested Ant script has> completed, but the outer <java> task doesn't shut down. Interestingly,> the extra java.exe for the nested Ant script disappears from the Windows> Task Manager at the same time as the BUILD SUCCESSFUL message, so it> seems that the outer Ant script running the <java> task hasn't detected> this somehow.> > Incidentally, the behaviour is identical if I use the <forget> task from> Ant-Contrib instead of the spawn="true" attribute.> > Can anyone suggest what is going wrong here?> > Thanks,> Keith> > > Axiom Systems Limited is a limited company registered in England and> Wales. Registered number: 2358771. Registered office: One Forbury> Square, The Forbury, Reading, Berks RG1 3EB> > ---------------------------------------------------------------------> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org> For additional commands, e-mail: user-help@ant.apache.org>
    _________________________________________________________________
    Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
    http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews

Related Discussions

Discussion Navigation
viewthread | post

2 users in discussion

Martin Gainty: 1 post Keith Hatton: 1 post