Not all application server supports hot deploy so you have to stop and start the server for deploying a new application or you just want to make sure that your server (or an other process) is running on your system while cruisecontrol is building a project. So it can be necessary to start an independent process like a server when bootstrapping or when building a project.
But if you simply start such a process with ants exec-task, cruisecontrol will wait for all processes which where started by ant to finish after the ant-script has done its work, even if you set the spawn-attribute true.
The idea ot handle this issue is to start the process "remotely" (even when starting a process on the same system). This has the effect that the new process is realy detached from the process by which it was started.
Here are tree ways to implement it.
1. Start the server, run tests and stop server in <parrallel>
see Running Servertests with Ant for details
2. Exec
- For Windows:
I have found a freeware-tool called PsExec. With this tool its is possible to execute processes remotely. But it works on localhost as well. The ant-task for starting the server or a complette framework via a batch-file looks like this (for localhost):
In this Example a batch-file will be execute on localhost and than ant will be waiting for a webserver to come up.
<target name="startingMyServer" description="Starting my server.">
<exec executable="psexec" dir="root/to/psexec" spawn="true">
<arg line="-u myuser -p mypassword -d -i c:\absolute\path\to\my\batchFile"/>
</exec>
<waitfor>
<http url="http:MyServer"/>
</waitfor>
<fail message="The server could not be started. (Timeout)"/>
</target>
- For all plattforms (Thanks to Greg Nwosu)
An other way (which should work on all plattforms on which ant-scripts can be executed) is to use the optinal ant-task sshexec. For this method you have to configure ssh keys but there are many ways to do this. The task looks like this:
<target name="startingMyServer" description="Starting my server.">
<sshexec host="localhostOrAnyOtherRemoteSystem"
username="myuser"
trust="yes"
keyfile="/path/to/key/file"
command="WhatEveryouWantToDo"/>
<waitfor>
<http url="http:MyServer"/>
</waitfor>
<fail message="The server could not be started. (Timeout)"/>
</target>
It works well for me and I hope it will help some of you.
3. Use daemon threads (which should work for Ant's <exec> task as well):
<parallel>
<daemons>
<java dir="${jboss.home}/bin"
classname="org.jboss.Main"
fork="true"
spawn="false">
<classpath>
<pathelement path="${java.home}/lib/tools.jar" />
<pathelement path="${jboss.home}/bin/run.jar" />
</classpath>
</java>
</daemons>
</parallel>