使用install4j的“Install Service”操作

时间:2016-06-02 11:11:01

标签: java install4j

我需要将tomcat安装为Windows服务并在安装期间启动服务。

最初我创建了install.bat& startService.bat文件并在安装期间使用install4j的“运行可执行文件或批处理文件”操作执行这些批处理文件。

为此,我必须将批处理文件保存在安装目录中。

所以我被要求使用“安装服务”& installa4j的“启动服务”操作,以便在安装位置不需要批处理文件。

任何人都可以帮助我,我在下面添加了批处理文件?

    @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 

1 个答案:

答案 0 :(得分:0)

您必须编写如下的Java类:

>>> s = """<Aug22-2008> <15:37:37> Bond Energy LDA -17.23014168 eV"""
>>> s.split()[5]
'-17.23014168'

并将其用作install4j中服务启动程序的主类。