程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> 如何讓 JAVA 程序在 NT 的服務中運行

如何讓 JAVA 程序在 NT 的服務中運行

編輯:關於JAVA

You can use the utility SRVANY.EXE, included with the NT resource Kit.

Installation of a service

copy SRVANY.EXE and install it as a NT services, like: INSTSRV MyServi

ce c:\tools\srvany.exe

configure via the Services applet("Startup..." dialog) of the Control

Panel as manual or automatic

set via via the Services applet the account for the service. If you ne

ed Access to the screen & keyboard, you must choose the LocalSystem ac

count and click the "Allow Service to Interact with Desktop".

run REGEDIT and create the following PARAMETERS key :

HKEY_LOCAL_MacHINE\SYSTEM\CurrentControlSet\Servics\MyService

Application=

AppParameters= (optional)

AppDirectory=

al)

To execute a Java program as a service:

Create the service with INSTSRV JavaService c:\tools\srvany.exe

Specify in the Control Panel if it`s manual or automatic

In the REGISTRY

HKEY_LOCAL_MacHINE\SYSTEM\CurrentControlSet\Servics\JavaService

Application=c:\jdk1.1\bin\Java.exe

AppParameters=c:\Java\classes\myClass

AppDirectory=c:\Java\classes

The benefits are :

Allow applications to survive logoff/logon sequences, hence saving ove

rhead of re-starting them for each new user

allow server to come-up and service requests even when no user is logg

ed on

allow applications to run and perform a task in a specific logon accou

nt, different from the currently logged-on user.

Starting and Stopping :

If configured as automatic, the user doesn`t need to start it explicit

ely: it is started automatically every time the system is re-booted. F

or manual services, the user may start a service with :

(with the SC.EXE utility) ex. SC start MyService or with NET START

MyService

SC stop MyService or NET STOP

MyService

To de-install a service :

INSTSRV MyService remove

Also in the Microsoft SDK 2.0, a package called com.ms.service that pr

ovides this functionality is included. Some utilitIEs and demos are in

cluded. Check the Microsoft Java Web site for more infos.

NOTE These Microsoft utilitIEs can`t be freely distributed. You may wa

nt to take a look at invoker, a freeware equivalent of MS srvany.exe f

or running executables as services.

----------------------------------------------------------------------

----------

Author: Real Gagnon

Author`s WebSite: http://tactika.com/realhome/realhome.Html

You can use the utility SRVANY.EXE, included with the NT resource Kit.

Installation of a service

copy SRVANY.EXE and install it as a NT services, like: INSTSRV MyServi

ce c:\tools\srvany.exe

configure via the Services applet("Startup..." dialog) of the Control

Panel as manual or automatic

set via via the Services applet the account for the service. If you ne

ed Access to the screen & keyboard, you must choose the LocalSystem ac

count and click the "Allow Service to Interact with Desktop".

run REGEDIT and create the following PARAMETERS key :

HKEY_LOCAL_MacHINE\SYSTEM\CurrentControlSet\Servics\MyService

Application=

AppParameters= (optional)

AppDirectory=

al)

To execute a Java program as a service:

Create the service with INSTSRV JavaService c:\tools\srvany.exe

Specify in the Control Panel if it`s manual or automatic

In the REGISTRY

HKEY_LOCAL_MacHINE\SYSTEM\CurrentControlSet\Servics\JavaService

Application=c:\jdk1.1\bin\Java.exe

AppParameters=c:\Java\classes\myClass

AppDirectory=c:\Java\classes

The benefits are :

Allow applications to survive logoff/logon sequences, hence saving ove

rhead of re-starting them for each new user

allow server to come-up and service requests even when no user is logg

ed on

allow applications to run and perform a task in a specific logon accou

nt, different from the currently logged-on user.

Starting and Stopping :

If configured as automatic, the user doesn`t need to start it explicit

ely: it is started automatically every time the system is re-booted. F

or manual services, the user may start a service with :

(with the SC.EXE utility) ex. SC start MyService or with NET START

MyService

SC stop MyService or NET STOP

MyService

To de-install a service :

INSTSRV MyService remove

Also in the Microsoft SDK 2.0, a package called com.ms.service that pr

ovides this functionality is included. Some utilitIEs and demos are in

cluded. Check the Microsoft Java Web site for more infos.

NOTE These Microsoft utilitIEs can`t be freely distributed. You may wa

nt to take a look at invoker, a freeware equivalent of MS srvany.exe f

or running executables as services.

--

很多在Windows下有C++開發經驗的兄弟在轉到Java時,都會問:怎麼使我寫的Java程序也能夠作為NT的服務運行呢?

其實有兩種解決方案:

1、MS本身提供的platform sdk for java 4.0中包含了大量的使用Java開發NT服務和COM的例子,不過需要MS的虛擬機和編譯器

2、使用Sun的標准JDK實現,可參見以下網址:

http://www.kcmultimedia.com/Javaserv/

該文的Java應用實際完成做注冊RMI對象的任務,當然,我們可以替換其為socket listener等等,不過要求開發者同時熟悉NT下服務的運做機制。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved