Ant task to automate the start of my server and application - ant

I want to write Ant task to automate the task of starting my server and then open Internet Explorer with the URL of my application.
Obviously I have to execute the startServer task first and then startApplication task.
But Ant is not coming out of startServer task even after starting the server to execute startApplication task.
Basically I want Ant to understand that startServer will not end and ANT has to come out of startServer task and runstartApplication task while startServer task is running in background.

My guess is that you have an exec task in startServer. Add spawn="true" to the exec. Ant will then execute the command in the background and continue without waiting for it to complete.

I agree with Aaron you can use exec to do this, you can also use waitfor to test your connection.
<exec executable="${jboss.startup.bat}" spawn="true"/>
<echo>Waiting to start</echo>
<waitfor maxwait="10" maxwaitunit="second" checkevery="5000">
<!-- try to detect when the server has started -->
<http url="${myurl}" />
</waitfor>
<echo>Started</echo>

You also need to be aware of the problems with exec'ing .bat files directly. Consult the manual page for the <exec> task for more information.

Related

How to terminate <exec> task in ANT after starting server in Windows

I'm trying to start a weblogic server using ant exec command.
After the operation triggers the exec process creates a child process i.e starts weblogic server. I wish to terminate the parent ant process after the server startup and keep alive the running Weblogic server.
I have tried using spawn="true" and task, but it does not help.
Also I am trying to call the ant buil.xml from eclipse.
I want to achieve that the task should start the server and then terminate the ant process and the calling java program should finish its execution from eclipse.
Following is my build.xml:
<target name="StartWeblogicServer" description="Starts the Weblogic Server" >
<exec dir="${DOMAIN_HOME}/bin" executable="cmd" failonerror="true" spawn="true">
<arg value="/c start startWeblogic.cmd" />
</exec>
</target>
The above code starts a weblogic server in a seperate command prompt. However the eclipse does not terminate the running program as the ant process is not terminate after the execution of task.
Please help.

about ant sshexec

how to specify command in sshexec task of ant to execute an ant task on a remote server machine. like for example:
<sshexec host="somehost"
username="dude"
keyfile="${user.home}/.ssh/id_dsa"
commandResource="to_run"/>
in above code what would be in the command attribute while trying to perform an ant task on a remote server machine, and also if the ant task is to deploy an application
please help me out on this one as the appache site is not of much help.

Ant exec task as another user

I would like to execute a shell script from an ant build (I saw the exec task seems to do it), but this script has to be executed from a user different thant the one launching ant. Is there a way to do this?
You could use the sshsexec task. Connect locally or to a remote machine:
<sshexec host="localhost"
username="dude"
password="yo"
command="touch somefile"/>
This task will require the optional jsch.jar to be installed in your ANT lib.
Specifying a pirvate key would enable a password-less login.
Couldn't you execute, from ant, a script that executes the actual script using sudo? See How to pass the password to su/sudo/ssh without overriding the TTY? for how to pass the password from the command line.

ANT how to fork task execution?

I need to fork a new process for a specific ant task. I dont see a fork attribute in the taskdef how do I do it ?
I should be clearer, I am not talking about executing ANT in a forked process:
I have an ant task X, which I need to run in a forked process. Its some third party task which i use with taskdef X and then use this way
Is there anyway to tell any that anytime i use that task please fork the process and run ?
See Running Ant via Java in the Ant manual.

Can't specify Cobertura datafile location for server running under Ant?

I have an Ant build script that instruments some jar files, starts some servers using those jars files and then runs an integration test suite of junit tests against them.
I want to capture the cobertura.ser file from each server in a separate file.
The servers need to have their working directory set so they can pick up config files. It's a requirement of the system that the classpath must not be used to pick up these files.
Setting the net.sourceforge.cobertura.datafile system property allows the datafile to be set, and this works ok, until the "dir" property is set on the ant java task. Once dir is set, the server starts correctly, the test suite runs OK, but when the server shuts down no data file is written.
Here's a fragment of the build.xml:
<parallel>
<daemons>
<java fork="true" dir="src\main\resources\conf\my.server" classname="my.Server">
<sysproperty key="net.sourceforge.cobertura.datafile" file="target\cobertura.ser" />
<classpath>
...
</classpath>
<arg value="-server" />
</java>
...more servers...
...run junit tests...
</daemons>
</parallel>
The answer is to not run the servers as daemons. We were doing this so that the servers were automatically shut down when the junit task had completed, but in reality, the Cobertura instrumentation wasn't picking up the fact that the servers were shutting down and so never wrote out the various cobertura.ser files.
The solution was to remove the daemons task, and to add an explicit server shutdown mechanism which we could call from Ant once the tests were complete.

Resources