Ant task to install tomcat service

ADSENSE HERE!
If you are familiar to run Apache Tomcat as Windows service, you can install it with the ant task. build.xml file sample under the cut line.



First of all let's do some properties setup:



catalina.home=d:/java/tomcat-6.0.18
tomcat.executable=${catalina.home}/bin/tomcat6.exe
tomcat.service.executable=\
${catalina.home}/bin/service.bat
tomcat.service.name=myproject
# parameters that will be used in the jvm
tomcat.service.jvm.ms=128
tomcat.service.jvm.mx=256


Service startup task consists of 5 exec commands:

  • Stop service if currently running

  • Delete service if installed

  • Install service with bat script

  • Update service with some parameters

  • Start service



Here is the implementation:



<target name="tomcat.service.install" description="Install tomcat service">

<exec command="net stop ${tomcat.service.name}"
failifexecutionfails="false"
failonerror="false"/>

<exec command="${tomcat.executable} //DS//${tomcat.service.name}"
failifexecutionfails="false"
failonerror="false"/>
<exec executable="${tomcat.service.executable}"
failifexecutionfails="true" failonerror="true">
<env key="CATALINA_HOME" value="${catalina.home}"/>
<arg value="install"/>
<arg value="${tomcat.service.name}"/>
</exec>
<exec executable="${tomcat.executable}">
<arg value="//US//${tomcat.service.name}"/>
<arg value="--JvmMs=${jvm.ms}"/>
<arg value="--JvmMx=${jvm.mx}"/>
<arg value="--Startup=auto"/>
</exec>
<exec command="net start ${tomcat.service.name}"
failifexecutionfails="true" failonerror="true"/>
</target>




ADSENSE HERE!

2 comments:

  1. Hi, nice post. I have been thinking about this issue,so thanks for blogging. I will definitely be subscribing to your posts. Keep up the good posts

    ReplyDelete
  2. lol a number of the feedback people make are kinda silly, now and again i think about whether they really read the subject material and threads before writing a comment or if perhaps they take a moment to read over the titles and prepare the very first thing that pops into their heads. anyways, it's pleasurable to browse through keen commentary from time to time as opposed to the exact same, old blog vomit which i often see on the internet i'm off to take up a smattering of hands of facebook poker good bye

    ReplyDelete

Komen dong, tapi yang sopan dan tidak spam ya

Arsip Blog

Copyright © Spesial Unik. All rights reserved. Template by CB. Theme Framework: Responsive Design