我在用JAVA编写一个系统的安装程序,要安装的系统中包括一个服务程序,用C++写的,可跨平台运行!请问如何在安装程序中自动注册为服务并可自动运行?
在Linux上可以通过init文件来实现,但是在nt上,是用scmmanager来维护服务的,不知道java中有没有相关的类可以用来对SCM进行管理?
请高手支招,最好给出源码.谢了
------解决方案--------------------
帮楼主顶上去
------解决方案--------------------
不懂,只有帮顶
------解决方案--------------------
看看能否直接写注册表
专门有个地方描述服务的
------解决方案--------------------
可以使用批处理文件,如下:
- BatchFile code
@echo offrem Licensed to the Apache Software Foundation (ASF) under one or morerem contributor license agreements. See the NOTICE file distributed withrem this work for additional information regarding copyright ownership.rem The ASF licenses this file to You under the Apache License, Version 2.0rem (the "License"); you may not use this file except in compliance withrem the License. You may obtain a copy of the License atremrem http://www.apache.org/licenses/LICENSE-2.0remrem Unless required by applicable law or agreed to in writing, softwarerem distributed under the License is distributed on an "AS IS" BASIS,rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.rem See the License for the specific language governing permissions andrem limitations under the License.if "%OS%" == "Windows_NT" setlocalrem ---------------------------------------rem NT Service Install/Uninstall scriptremrem Optionsrem install Install the service using Tomcat6 as service name.rem Service is installed using default settings.rem remove Remove the service from the System.remrem name (optional) If the second argument is present it is consideredrem to be new service name remrem $Id: service.bat 600659 2007-12-03 20:15:09Z jim $rem ---------------------------------------rem Guess CATALINA_HOME if not definedset CURRENT_DIR=%cd%if not "%CATALINA_HOME%" == "" goto gotHomeset CATALINA_HOME=%cd%if exist "%CATALINA_HOME%\bin\tomcat6.exe" goto okHomerem CD to the upper dircd ..set CATALINA_HOME=%cd%:gotHomeif exist "%CATALINA_HOME%\bin\tomcat6.exe" goto okHomeecho The tomcat.exe was not found...echo The CATALINA_HOME environment variable is not defined correctly.echo This environment variable is needed to run this programgoto endrem Make sure prerequisite environment variables are setif not "%JAVA_HOME%" == "" goto okHomeecho The JAVA_HOME environment variable is not definedecho This environment variable is needed to run this programgoto end :okHomeif not "%CATALINA_BASE%" == "" goto gotBaseset CATALINA_BASE=%CATALINA_HOME%:gotBase set EXECUTABLE=%CATALINA_HOME%\bin\tomcat6.exerem Set default Service nameset SERVICE_NAME=Tomcat6set PR_DISPLAYNAME=Apache Tomcatif "%1" == "" goto displayUsageif "%2" == "" goto setServiceNameset SERVICE_NAME=%2set PR_DISPLAYNAME=Apache Tomcat %2:setServiceNameif %1 == install goto doInstallif %1 == remove goto doRemoveif %1 == uninstall goto doRemoveecho Unknown parameter "%1":displayUsageecho.echo Usage: service.bat install/remove [service_name]goto end:doRemoverem Remove the service"%EXECUTABLE%" //DS//%SERVICE_NAME%echo The service '%SERVICE_NAME%' has been removedgoto end:doInstallrem Install the serviceecho Installing the service '%SERVICE_NAME%' ...echo Using CATALINA_HOME: %CATALINA_HOME%echo Using CATALINA_BASE: %CATALINA_BASE%echo Using JAVA_HOME: %JAVA_HOME%rem Use the environment variables as an examplerem Each command line option is prefixed with PR_set PR_DESCRIPTION=Apache Tomcat Server - http://tomcat.apache.org/set PR_INSTALL=%EXECUTABLE%set PR_LOGPATH=%CATALINA_BASE%\logsset PR_CLASSPATH=%CATALINA_HOME%\bin\bootstrap.jarrem Set the server jvm from JAVA_HOMEset PR_JVM=%JAVA_HOME%\jre\bin\server\jvm.dllif exist "%PR_JVM%" goto foundJvmrem Set the client jvm from JAVA_HOMEset PR_JVM=%JAVA_HOME%\jre\bin\client\jvm.dllif exist "%PR_JVM%" goto foundJvmset PR_JVM=auto:foundJvmecho Using JVM: %PR_JVM%"%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stopif not errorlevel 1 goto installedecho Failed installing '%SERVICE_NAME%' servicegoto end:installedrem Clear the environment variables. They are not needed any more.set PR_DISPLAYNAME=set PR_DESCRIPTION=set PR_INSTALL=set PR_LOGPATH=set PR_CLASSPATH=set PR_JVM=rem Set extra parameters"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvmrem More extra parametersset PR_LOGPATH=%CATALINA_BASE%\logsset PR_STDOUTPUT=autoset PR_STDERROR=auto"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-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 128 --JvmMx 256echo The service '%SERVICE_NAME%' has been installed.:endcd %CURRENT_DIR%