Glassfish安裝為windows系統(tǒng)服務
Glassfish 附帶一個名為 appservService.exe 的 Windows 可執(zhí)行文件,它可與 Windows 服務控制器通信。其工作方式類似于 Java Service Wrapper 等程序。您為 Glassfish 創(chuàng)建的 Windows 服務使用幾個參數(shù)來啟動 appservService.exe,這些參數(shù)告知它在啟動和停止時要執(zhí)行哪些 asadmin 命令。
Glassfish 并未附帶可為 appservService.exe 輕松創(chuàng)建 Windows 服務的工具,但是 Sun Java Application Server 9.x 的安裝程序有一個 "Install as a Windows service" 復選框。如果您要為 Glassfish 創(chuàng)建 Windows 服務,則該說明中給出了可從命令提示符運行的一個相當大的命令。如果 Glassfish 安裝路徑包含空格,例如 C:\Program Files\Sun\GlassfishV2
uff0c那么查找正確方法對轉(zhuǎn)義字符進行轉(zhuǎn)義就變得復雜而不是快速了。
GlassfishSvc.jar
Ryan de Laplante 提供了一個簡單的命令行工具,通過它可以輕而易舉地創(chuàng)建 Windows 服務。下載 GlassfishSvc.jar(源代碼),并將其復制到 Glassfish 安裝路徑(例如 C:\Program Files\Sun\GlassfishV2
uff09,然后從命令行運行以下命令:
- C:\Program Files\Sun\GlassfishV2>java -jar GlassfishSvc.jar -i
- glassfishsvc v1.0 (Aug 19 2007)
- Service name : GlassfishAppServer
- Glassfish installation path : C:\Program Files\Sun\GlassfishV2
- Glassfish domain : domain1
- Glassfish admin username : admin
- Installing service... Done.-i
參數(shù)將使用默認選項安裝服務。命令行參數(shù)的完整列表如下:
- glassfishsvc v1.0 (Aug 19 2007)
- DESCRIPTION:
- Installs and uninstalls a Windows service for Glassfish
- USAGE:
- java -jar glassfishsvc.jar [-i | -u] [OPTIONS]
- -i Installs a Windows service for Glassfish.
- -u Uninstalls a Windows service for Glassfish.
- -n name Name for the Windows service. Use double quotes around names
- that contain spaces. Defaults to GlassfishAppServer.
- -d path Directory where Glassfish is installed. Use double
- quotes around paths with spaces, and escape back slashes.
- Defaults to current directory.
- -m domain Name of the Glassfish domain to start and stop. Defaults to
- domain1.
- -a user Glassfish admin user name. Defaults to admin.
- -p pwd Glassfish admin password. A password.txt file will be created
- in the Glassfish install directory containing the password in
- plain text, and the Windows service will be configured to read
- from it. This is usually not necessary. If no password is passed
- in, the password.txt file will not be created.
- EXAMPLES:
- java -jar glassfishsvc.jar -i
- java -jar glassfishsvc.jar -i -p adminadmin
- java -jar glassfishsvc.jar -i -n MyServiceName -d "C:\\Program Files\\Sun\\Glassfish" -m myDomain -a admin5 -p secretpwd
- java -jar glassfishsvc.jar -u
- java -jar glassfishsvc.jar -u -n MyServiceName
- AUTHOR:
- Ryan de Laplante < ryan at ijws dot com>群集配置文件
如果您安裝了 Glassfish 群集配置文件,則 Glassfish 會在服務啟動時詢問管理員密碼。要避免詢問此問題,請在安裝服務時使用 -p 選項。在 Glassfish 根目錄中將創(chuàng)建 password.txt 文件,其中包含純文本形式的密碼。Windows 服務將配置為使用此文件,以便它可以在無人參與的情況下啟動。您應該確保在此文件創(chuàng)建后對其配置相應的 NTFS 安全性,以便未授權(quán)用戶對它沒有讀取或?qū)懭朐L問權(quán)限。
Windows 用戶注銷
默認情況下,JVM 可以捕獲來自 Windows 的指示 OS 正在關(guān)閉或用戶正在注銷的信號,并正常地自行關(guān)閉。這意味著,一旦用戶從 Windows 中注銷,Glassfish 服務便會關(guān)閉。這有違于使用 Windows 服務的初衷,因此需要使用 -Xrs JVM 選項關(guān)閉此 JVM 功能。
打開 < GF_HOME>\domains\domain1\config\domain.xml 文件,并查找含有大量 < jvm-options>某個 JVM 選項< /jvm-options> 行的部分。在該部分中添加以下行:
< jvm-options>-Xrs< /jvm-options>保存并關(guān)閉 domain.xml。如果 Glassfish 服務已在運行,請重新啟動它以使更改生效。
注意:有報告指出,在某些 Windows 2003 Server 安裝中將 -Xrs jvm-option 添加到 domain.xml 無法解決此問題。所報告的解決方案是將 jvm 選項添加到 < GF_HOME>\lib\processLauncher.xml:
- < process name="as9-server">
- ...
- < sysproperty key="-Xrs"/>
- ...
【編輯推薦】