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
<targetname="dpl">
<!-- defining variables used in this target-->
<propertyname="url"value="http://yourhost:8181/app_name/home";/>
<propertyname="serverbase"value="D:/your_server_base_path_here"/>
<propertyname="serverdeploy"value="${serverbase}/deploy"/>
<propertyname="app_war_dir"value="d:/application_war"/>
<propertyname="appname"value="myapp"/>
<!--unwar the war file taken from app_war_dir , in the serverdeploy location as war extension -->
<echo>START @ deploying in server</echo>
<unwarsrc="${app_war_dir}/${appname}.war"dest="${serverdeploy}/${appname}.war"/>
<echo> END @ deploying in server</echo>
<!-- delete all the temp/work/log files-->
<echo>START @ deleting tmp,work,log</echo>
<deletedir="${serverbase}/tmp"/>
<deletedir="${serverbase}/work"/>
<deletedir="${serverbase}/log"/>
<echo> END @ deleting tmp,work,log</echo>
<!-- start the server -->
<echo>START @ server starting</echo>
<!-- a parallel task will run the tasks within parallel -->
<parallel>
<execexecutable="cmd"dir="D:/servers/jboss-4.2.3.GA/bin">
<argvalue="/c start run.bat "/>
</exec>
<!-- Sequential task will execute all the task defined inside in a sequence -->
<sequential>
<!-- 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 -->
<waitformaxwait="5"maxwaitunit="minute"checkeveryunit="second"checkevery="1">
<and>
<httpurl="${url}";errorsBeginAt="400"/>
</and>
</waitfor>
<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 -->
<execexecutable="cmd">
<argVALUE="/C start http://localhost:8181/application/index.do";/>
</exec>
<echo>voila </echo>
</sequential>
</parallel>
</target>
The above target is tested with JBOSS 4.2.3 and on a windows machine. You must modify the variables to get it running.