Wednesday, April 7, 2010

Tomcat as Service - Service Startup on System Startup

If you want to start tomcat on system startup automatically, you can create tomcat service as follows. This is part of my bat file which I invoke using iZpack (an open source installer tool).

@echo on

"%~1\Apache Software Foundation\bin\tomcat6" //IS//Tomcat6 --Startup auto --JvmMx 516 --JvmMs 256 --Install "%~1\Apache Software Foundation\bin\tomcat6.exe" --Jvm auto --StartMode jvm --StopMode jvm --StartClass org.apache.catalina.startup.Bootstrap --StartParams start --StopClass org.apache.catalina.startup.Bootstrap --StopParams stop --StartPath "%~1\Apache Software Foundation" --StopPath "%~1\Apache Software Foundation" --Classpath "%~1\Apache Software Foundation\bin\bootstrap.jar"

if not errorlevel 0 goto unInstall else goto end
:unInstall
echo uninstalling.......

"%~1\Apache Software Foundation\bin\tomcat6" //DS//Tomcat6

"%~1\Apache Software Foundation\bin\tomcat6" //IS//Tomcat6 --Startup auto --JvmMx 516 --JvmMs 256 --Install "%~1\Apache Software Foundation\bin\tomcat6.exe" --Jvm auto --StartMode jvm --StopMode jvm --StartClass org.apache.catalina.startup.Bootstrap --StartParams start --StopClass org.apache.catalina.startup.Bootstrap --StopParams stop --StartPath "%~1\Apache Software Foundation" --StopPath "%~1\Apache Software Foundation" --Classpath "%~1\Apache Software Foundation\bin\bootstrap.jar"

:end
echo exiting....
In the above code, %~1 is for passing a runtime variable whose value has spaces. In my case 1 contained the installation directory path, with spaces - "C:\Program Files\"
 
Save the code as a .bat file and execute it. Make sure that you have already installed tomcat in the location as mentioned in the code. In my case, Tomcat was installed under "C:\Program Files\".


0 comments:

Post a Comment