For many of the time I wanted to write Ant task that will help me deploy the my application into the server and start the server, because of tedious process like:
- Copy the war into the server.
- Explode the war ie unzip the war file into the server ,which helps in quick modification to jsp or xml files for my application.
- Delete the server logs and temporary files.
- More over I also wanted to start the the server from ant !!!! , and start the browser as soon as the server is ready to serve without any problem with my specified URL.
Well last point was bit challenging, since we need to have intelligence in the code to identify if the server is ready to server the page. Here is the ant target , which will do the job for you. There are inline comments to help you understand what each task
<!-- defining variables used in this target-->
<!--unwar the war file taken from app_war_dir , in the serverdeploy location as war extension -->
<echo>START @ deploying in server</echo>
<echo> END @ deploying in server</echo>
<!-- delete all the temp/work/log files-->
<echo>START @ deleting tmp,work,log</echo>
<echo> END @ deleting tmp,work,log</echo>
<!-- start the server -->
<echo>START @ server starting</echo>
<!-- a parallel task will run the tasks within parallel -->
<argvalue="/c start run.bat "/>
<!-- Sequential task will execute all the task defined inside in a sequence -->
<!-- Waitfor task below waits, for 5 mins (the usual time my server starts up, configure your as per your requirement)and then starts checking the http ping in every 1 second to see if there is an http response code 400 or above -->
<echo>Server seems to have responded , so start the browswer</echo>
<!-- execute the following task ie to get the browser if the above task passes -->
<argVALUE="/C start http://localhost:8181/application/index.do";/>
The above target is tested with JBOSS 4.2.3 and on a windows machine. You must modify the variables to get it running.