当前位置: 技术问答>java相关
java程序如何做成windows服务程序,在线等候
来源: 互联网 发布时间:2015-09-21
本文导语: 在C中可以调用MFC的API来实现做成服务的效果,那么在java中是否也可以去掉黑乎乎的运行窗口,而做成服务形式呢,更重要的是这样的话不用在重起服务器的时候就不用手工启动你要启动的java程序了. | ...
在C中可以调用MFC的API来实现做成服务的效果,那么在java中是否也可以去掉黑乎乎的运行窗口,而做成服务形式呢,更重要的是这样的话不用在重起服务器的时候就不用手工启动你要启动的java程序了.
|
有一个程序是专门把java程序做成服务的。是一个exe文件,加不同的参数。
tomcat的bin下面的tomcat.exe就是这个文件。其实是javaservice.exe。
给你个tomcat的例子,如果想要全部文档的程序给我发的信,我给你发过去。
foreverxin@21cn.com
Tomcat is a JSP engine and was the primary reason that JavaService was created. It is a pure Java application that is ideally used as a service, but comes with no native ability to do so. The following example shows how JavaService can be used to run Tomcat 3.1 as an NT service. The ideas shown here apply to using JavaService with any Java application that needs to run as an NT service. {JDK_HOME} is the location of your JDK and {TOMCAT_HOME} is the location of your Tomcat installation.
Copy the JavaService.exe file into the{TOMCAT_HOME}bin directory as tomcat.exe.
Start a command prompt and change to the directory {TOMCAT_HOME}bin.
Run the following command:
tomcat.exe -install Tomcat
{JDK_HOME}jrebin{hotspot|server|classic}jvm.dll
-Djava.class.path={TOMCAT_HOME}binbootstrap.jar;{TOMCAT_HOME}binservlet.jar;{JDK_HOME}libtools.jar
-Dcatalina.home={TOMCAT_HOME}
-start org.apache.catalina.startup.Bootstrap
-params start
-stop org.apache.catalina.startup.Bootstrap
-params stop
-out {TOMCAT_HOME}logsstdout.log
-err {TOMCAT_HOME}logsstderr.log
tomcat的bin下面的tomcat.exe就是这个文件。其实是javaservice.exe。
给你个tomcat的例子,如果想要全部文档的程序给我发的信,我给你发过去。
foreverxin@21cn.com
Tomcat is a JSP engine and was the primary reason that JavaService was created. It is a pure Java application that is ideally used as a service, but comes with no native ability to do so. The following example shows how JavaService can be used to run Tomcat 3.1 as an NT service. The ideas shown here apply to using JavaService with any Java application that needs to run as an NT service. {JDK_HOME} is the location of your JDK and {TOMCAT_HOME} is the location of your Tomcat installation.
Copy the JavaService.exe file into the{TOMCAT_HOME}bin directory as tomcat.exe.
Start a command prompt and change to the directory {TOMCAT_HOME}bin.
Run the following command:
tomcat.exe -install Tomcat
{JDK_HOME}jrebin{hotspot|server|classic}jvm.dll
-Djava.class.path={TOMCAT_HOME}binbootstrap.jar;{TOMCAT_HOME}binservlet.jar;{JDK_HOME}libtools.jar
-Dcatalina.home={TOMCAT_HOME}
-start org.apache.catalina.startup.Bootstrap
-params start
-stop org.apache.catalina.startup.Bootstrap
-params stop
-out {TOMCAT_HOME}logsstdout.log
-err {TOMCAT_HOME}logsstderr.log
|
你还是必须用VC写一个服务的shell, 然后再这个shell中调用java虚拟机。
tomcat就是这么做的。
tomcat就是这么做的。
|
用RMI也许可以,
把你的java程序嵌入RMI server端的impl中,这样它就可以像服务一样随时被
调用,然后你可以把rmiregistry 和运行rmi server都做成bat, 放在windows的启动里就可以了。我以前做过类似的事情。
把你的java程序嵌入RMI server端的impl中,这样它就可以像服务一样随时被
调用,然后你可以把rmiregistry 和运行rmi server都做成bat, 放在windows的启动里就可以了。我以前做过类似的事情。
|
注:默认安装为服务是马上启动,并且是自动运行的。
前一阵正好做这个,所以知道的多点。
前一阵正好做这个,所以知道的多点。