Short answer: It is NOT possible, at least there is no easy way to do it, just as it was discussed on the page Shashank Kadne pointed out. Other than starting Tomcat via startup.bat
script and placing you code (or a call to your BAT file) in the setenv.bat
file in the same folder as startup.bat
.
If you are trying to run applications like Jenkins, Artifactory and alike on a single Tomcat installation - as discussed on that page - a better way would be to create a Tomcat Server Instance (also known as CATALINA_BASE
) for each additional application.
This way you can have each application as a Windows Service and control it as a service.
Assumptions:
You Java is installed at C:\Program Files\Java\jdk-7.0_03
.
You Tomcat is installed at C:\Program Files\Apache\Tomcat 7
.
You want e.g. Jenkins server to be at C:\Program Files\My Jenkins
.
Start cmd.exe
, and do the following:
C:\Users\me> set "JAVA_HOME=C:\Program Files\Java\jdk-7.0_03"
C:\Users\me> set "CATALINA_HOME=C:\Program Files\Apache\Tomcat 7"
C:\Users\me> set "CATALINA_BASE=C:\Program Files\My Jenkins"
C:\Users\me> cd "%CATALINA_BASE%"
C:\Program Files\My Jenkins> mkdir "%CATALINA_BASE%\bin"
C:\...Jenkins> mkdir "%CATALINA_BASE%\conf"
C:\...Jenkins> mkdir "%CATALINA_BASE%\lib"
C:\...Jenkins> mkdir "%CATALINA_BASE%\logs"
C:\...Jenkins> mkdir "%CATALINA_BASE%\temp"
C:\...Jenkins> mkdir "%CATALINA_BASE%\webapps"
C:\...Jenkins> mkdir "%CATALINA_BASE%\work"
C:\...Jenkins> copy "%CATALINA_HOME%\conf\*.*" "%CATALINA_BASE%\conf"
C:\...Jenkins> copy "%CATALINA_HOME%\bin\*.exe" "%CATALINA_BASE%\bin"
C:\...Jenkins> copy "%CATALINA_HOME%\bin\tomcat-juli.jar" "%CATALINA_BASE%\bin"
C:\...Jenkins> cd bin
C:\...Jenkins> ren tomcat7.exe jenkins.exe
C:\...Jenkins> ren tomcat7w.exe jenkinsw.exe
The next command should be in a single line
C:\...Jenkins> jenkins.exe //IS//Jenkins --DisplayName "Jenkins CI"
--Description "Jenkins Continuous Integration Server on Tomcat"
--Startup auto --JavaHome "%JAVA_HOME%" --StartMode jvm --StopMode jvm
--StartClass org.apache.catalina.startup.Bootstrap
--StopClass org.apache.catalina.startup.Bootstrap
--StartParams start --StopParams stop
--Classpath "%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_BASE%\bin\tomcat-juli.jar;"
--StdOutput auto --StdError auto --LogLevel INFO
--LogPath "%CATALINA_BASE%\logs"
--JvmOptions -Xrs;-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;
You should now have the Jenkins CI
service in your "Services" window.
Deploy the Jenkins web application (WAR
file) into %CATALINA_BASE%\webapps
.
The steps I gave above are coming "from the the head" and are not tested, I might have missed a parameter or two. That is why there is the %CATALINA_BASE%\bin\jenkinsw.exe
- start it and tweak the parameters until the server is working.