I have a requirement to install tomcat as windows service and start the service during installation.
Initially I have created install.bat & startService.bat files and executing these batch files during installation using "run executable or batch file" action of install4j.
For this I had to keep the batch file in the installation directory.
So I was asked to use "Install Service" & "start service" action of installa4j so that batch file are not required in installation location.
Can any one help me, I have added the batch file below?
@echo off
setlocal
set "DATA_PATH=%~dp0data"
set "CATALINA_HOME=%~dp0tomcat"
set "CATALINA_BASE=%CATALINA_BASE%"
set "JRE_HOME=%~dp0jre"
set "EXECUTABLE=%CATALINA_HOME%\bin\sampleService.exe"
set SERVICE_NAME=sampleService
set DISPLAYNAME=sample Service
echo Installing the service '%SERVICE_NAME%'
echo Using CATALINA_HOME: "%CATALINA_HOME%"
echo Using CATALINA_BASE: "%CATALINA_HOME%"
echo Using JAVA_HOME: "%JAVA_HOME%"
echo Using JRE_HOME: "%JRE_HOME%"
set "JVM=%JRE_HOME%\bin\server\jvm.dll"
if exist "%JVM%" goto foundJvm
set "JVM=%JRE_HOME%\bin\client\jvm.dll"
if exist "%JVM%" goto foundJvm
set JVM=auto
:foundJvm
echo Using JVM: "%JVM%"
set "CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jar;
%CATALINA_BASE%\bin\tomcat-juli.jar"
if not "%CATALINA_HOME%" == "%CATALINA_BASE%"
set "CLASSPATH=%CLASSPATH%;%CATALINA_HOME%\bin\tomcat-juli.jar"
"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
--Description "tomcat 8" ^
--DisplayName "%DISPLAYNAME%" ^
--Install "%EXECUTABLE%" ^
--Startup auto ^
--LogPath "%CATALINA_BASE%\logs" ^
--StdOutput auto ^
--StdError auto ^
--Classpath "%CLASSPATH%" ^
--Jvm "%JVM%" ^
--StartMode jvm ^
--StopMode jvm ^
--StartPath "%CATALINA_HOME%" ^
--StopPath "%CATALINA_HOME%" ^
--StartClass org.apache.catalina.startup.Bootstrap ^
--StopClass org.apache.catalina.startup.Bootstrap ^
--StartParams start ^
--StopParams stop ^
--JvmOptions
"-Dconceptor.datapath=%DATA_PATH%;-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" ^
--JvmMs 1024 ^
--JvmMx 2048
if not errorlevel 1 goto installed
echo Failed installing '%DISPLAYNAME%' service
goto end
:installed
echo The service '%DISPLAYNAME%' has been installed.
:end
cd "%CURRENT_DIR%"
pause
You would have to write a Java class like this:
class MainClass {
public static void main(String[] args) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
org.apache.catalina.startup.Bootstrap("stop");
}
});
org.apache.catalina.startup.Bootstrap("start");
}
}
and use it as a main class for the service launcher in install4j.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.