将 Jetty 7 作为 Windows 服务运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2094429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running Jetty 7 as Windows Service
提问by tuler
Did Jetty 7 drop support to run as a service using Java Service Wrapper? What options do I have now?
Jetty 7 是否不再支持使用 Java Service Wrapper 作为服务运行?我现在有哪些选择?
回答by crowne
@glb, thanks for pointing out apache commons-daemon Procrun.
Its working great for me on Windows 7 64 Bit, here's how I set it up.
@glb,感谢您指出 apache commons-daemon Procrun。
它在 Windows 7 64 位上非常适合我,这是我的设置方式。
For more info see
有关更多信息,请参阅
- procrunpage as per link from @glb
- jetty help screen > java -jar start.jar --help
- 根据@glb 链接的procrun页面
- 码头帮助屏幕 > java -jar start.jar --help
REM 1. Open command prompt as Administrator
mkdir C:\java\apache-commons-daemon
REM 2. Download commons-daemon binaries for windows to directory above from
REM http://www.apache.org/dist/commons/daemon/binaries/windows/commons-daemon-1.0.15-bin-windows.zip
REM 3. unzip which will create C:\java\apache-commons-daemon\commons-daemon-1.0.5-bin-windows
mkdir C:\java\jetty
REM 4. Download jetty to directory above from
REM http://download.eclipse.org/jetty/7.4.2.v20110526/dist/jetty-distribution-7.4.2.v20110526.zip
REM 5. install / unzip which will create C:\java\jetty\jetty-distribution-7.4.2.v20110526
REM 6. Verify that jetty can be started
cd C:\java\jetty\jetty-distribution-7.4.2.v20110526
java -jar start.jar
REM Look for any obvious errors on the console
REM Open a browser at http://localhost:8080/
REM You should be presented with the Jetty Start Page,
REM and be able to execute the Hello World Servlet
REM OK, that's enough,
REM come back to the command prompt and ctrl-C to stop the jetty server
REM 7. Copy and rename commons-daemon binaries into the JETTY_HOME directory structure
REM Note that the GUI manager is copied to JETTY_HOME,
REM and the service exe is copied to JETTY_HOME\bin
REM Note that both binaries get the same target name,
REM but are placed in different directories
REM This is just makes it easier to launch the GUI manager
REM by not having to provide command line arguments
REM Note that I have selected the amd64\prunsrv.exe as the service exe,
REM I am running on Windows 7 64 bit Intel i7 Xeon
cd C:\java\jetty\jetty-distribution-7.4.2.v20110526
copy \java\apache-commons-daemon\commons-daemon-1.0.5-bin-windows\prunmgr.exe .\JettyService.exe
copy \java\apache-commons-daemon\commons-daemon-1.0.5-bin-windows\amd64\prunsrv.exe .\bin\JettyService.exe
REM 8. Time to install the service
bin\JettyService //IS//JettyService --DisplayName="Jetty Service" --Install=C:\java\jetty\jetty-distribution-7.4.2.v20110526\bin\JettyService.exe --LogPath=C:\java\jetty\jetty-distribution-7.4.2.v20110526\logs --LogLevel=Debug --StdOutput=auto --StdError=auto --StartMode=Java --StopMode=Java --Jvm=auto ++JvmOptions=-Djetty.home=C:\java\jetty\jetty-distribution-7.4.2.v20110526 ++JvmOptions=-DSTOP.PORT=8087 ++JvmOptions=-DSTOP.KEY=downB0y ++JvmOptions=-Djetty.logs=C:\java\jetty\jetty-distribution-7.4.2.v20110526\logs ++JvmOptions=-Dorg.eclipse.jetty.util.log.SOURCE=true ++JvmOptions=-XX:MaxPermSize=128M ++JvmOptions=-XX:+CMSClassUnloadingEnabled ++JvmOptions=-XX:+CMSPermGenSweepingEnabled --Classpath=C:\java\jetty\jetty-distribution-7.4.2.v20110526\start.jar --StartClass=org.eclipse.jetty.start.Main ++StartParams=OPTIONS=All ++StartParams=C:\java\jetty\jetty-distribution-7.4.2.v20110526\etc\jetty.xml ++StartParams=C:\java\jetty\jetty-distribution-7.4.2.v20110526\etc\jetty-deploy.xml ++StartParams=C:\java\jetty\jetty-distribution-7.4.2.v20110526\etc\jetty-webapps.xml ++StartParams=C:\java\jetty\jetty-distribution-7.4.2.v20110526\etc\jetty-contexts.xml ++StartParams=C:\java\jetty\jetty-distribution-7.4.2.v20110526\etc\jetty-testrealm.xml --StopClass=org.eclipse.jetty.start.Main ++StopParams=--stop
REM 9. Test that the service starts at the command prompt
bin\JettyService //TS
REM 10. To delete the service uncomment the line below
REM bin\JettyService //DS
REM 11. Now launch the GUI manager to check the parameter settings
JettyService.exe
REM You can use the GUI to start and stop the service, and to change the settings
REM If you want the GUI exe to have a different name to the service exe,
REM then close the GUI and uncomment and run the line below
REM ren JettyService.exe JettyServiceMgr.exe
REM To launch the renamed GUI uncomment and run the line below
REM JettyServiceMgr.exe //ES//JettyService
done!
完毕!
回答by Paul McKenzie
In the latest stable version of Java Service Wrapper(JSW 3.4.1) there's WrapperJarApp method of integration:
在Java Service Wrapper(JSW 3.4.1)的最新稳定版本中,有 WrapperJarApp 集成方法:
This is part of my configuration:
这是我配置的一部分:
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperJarApp
wrapper.java.classpath.1=%WRAPPER_HOME%/lib/*.jar
wrapper.java.classpath.2=%JETTY_HOME%/lib/*.jar
wrapper.java.classpath.3=%JETTY_HOME%/start.jar
wrapper.java.library.path.1=%WRAPPER_HOME%/lib
wrapper.app.parameter.1=%JETTY_HOME%/start.jar
wrapper.app.parameter.2=%JETTY_HOME%/etc/jetty.xml
# other config params as needed
回答by glb
回答by user432024
You can get the src from: http://svn.codehaus.org/jetty/jetty/branches/jetty-7/jetty-win32/and build it yourself.
您可以从以下位置获取 src:http: //svn.codehaus.org/jetty/jetty/branches/jetty-7/jetty-win32/并自行构建。
But I manually installed the wrapper as any “standard” wrapper installation.
但是我手动安装了包装器作为任何“标准”包装器安装。
Took the original Jetty-Service.conf file and changed:
获取原始 Jetty-Service.conf 文件并更改:
wrapper.java.mainclass=org.mortbay.jetty.win32service.JettyServiceWrapperListener to wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
wrapper.java.mainclass=org.mortbay.jetty.win32service.JettyServiceWrapperListener 到 wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
And added…
并补充说……
wrapper.app.parameter.1=org.eclipse.jetty.start.Main <-- Main class wrapper.app.parameter.2=../etc/jetty.xml wrapper.app.parameter.x=../etc/jetty-x.xml <--Any additional config files you wish to include… wrapper.app.parameter.y=../etc/jetty-y.xml
wrapper.app.parameter.1=org.eclipse.jetty.start.Main <-- 主类 wrapper.app.parameter.2=../etc/jetty.xml wrapper.app.parameter.x=../etc /jetty-x.xml <--您希望包含的任何其他配置文件... wrapper.app.parameter.y=../etc/jetty-y.xml
Seems to start fine and it seems to shutdown gracefully too.
似乎开始正常,似乎也可以正常关闭。
回答by Celso Dantas
I had a problema running @crowne's code for install the service (I'm running Jetty 8.1.0). Just needed to change -StartMode=Java --StopMode=Java
to -StartMode=jvm --StopMode=jvm
and remove ++JvmOptions=-XX:+CMSPermGenSweepingEnabled
.
我在运行@crowne 的安装服务代码时遇到了问题(我正在运行 Jetty 8.1.0)。只需要更改-StartMode=Java --StopMode=Java
为-StartMode=jvm --StopMode=jvm
并删除++JvmOptions=-XX:+CMSPermGenSweepingEnabled
.
After that I created a create_jetty_service.bat at the jetty/bin folder and run the file from there:
之后,我在 jetty/bin 文件夹中创建了一个 create_jetty_service.bat 并从那里运行该文件:
set jetty_home = C:\java\jetty\jetty-hightide-8.1.0.v20120127
JettyService //IS//JettyService --DisplayName="Jetty Service" ^
--Install=%jetty_home%\bin\JettyService.exe ^
--LogPath=%jetty_home%\logs ^
--LogLevel=Debug --StdOutput=auto --StdError=auto --StartMode=jvm --StopMode=jvm --Jvm=auto ^
++JvmOptions=-Djetty.home=%jetty_home% ^
++JvmOptions=-DSTOP.PORT=8087 ^
++JvmOptions=-DSTOP.KEY=downB0y ^
++JvmOptions=-Djetty.logs=%jetty_home%\logs ^
++JvmOptions=-Dorg.eclipse.jetty.util.log.SOURCE=true ^
++JvmOptions=-XX:MaxPermSize=256M ^
++JvmOptions=-XX:+CMSClassUnloadingEnabled ^
--Classpath=%jetty_home%\start.jar ^
--StartClass=org.eclipse.jetty.start.Main ^
++StartParams=OPTIONS=All ^
++StartParams=%jetty_home%\etc\jetty.xml ^
++StartParams=%jetty_home%\etc\jetty-deploy.xml ^
++StartParams=%jetty_home%\etc\jetty-webapps.xml ^
++StartParams=%jetty_home%\etc\jetty-contexts.xml ^
++StartParams=%jetty_home%\etc\jetty-testrealm.xml ^
--StopClass=org.eclipse.jetty.start.Main ++StopParams=--stop
Remember to run cmd.exe as administrator to the command take effect.
记得以管理员身份运行cmd.exe,命令生效。
回答by HIRUKAWA Ryo
You can run as a Windows service Jetty can be used to exewrap.
Jetty Windows Service all-in-one packages are also distributed.
您可以作为 Windows 服务运行 Jetty 可用于 exewrap。
Jetty Windows Service 多合一软件包也已分发。
回答by Snekse
If you are in a bit of a locked down environment and need to stay within the Microsoft provided tool set, then srvany
, instsrv
and sc
are your friends. Unfortunately it often includes making registry edits. The nice thing is it's very flexible.
如果你是在一个位锁定的环境,需要在微软内住宿提供工具集,然后srvany
,instsrv
并且sc
是你的朋友。不幸的是,它通常包括进行注册表编辑。好处是它非常灵活。
Here's what I did recently to auto-start a Selenium Grid hub server.
这是我最近为自动启动 Selenium Grid 中心服务器所做的工作。
Copy srvany.exe
into c:\tools\srvany\srvany.exe
复制srvany.exe
到c:\tools\srvany\srvany.exe
Open cmd window as admin and run:
以管理员身份打开 cmd 窗口并运行:
$ cd C:\tools\srvany
$ sc create "Selenium Grid Hub Server" binPath= c:\tools\srvany\srvany.exe DisplayName= "Selenium Grid Hub Server"
RegEdit
注册编辑
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Selenium Grid Hub Server
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Selenium Grid Hub Server
Add a new key named Parameters
Under that key, add 3 new String Values named:
添加一个名为的新键Parameters
在该键下,添加 3 个名为的新字符串值:
Application
=>${JAVA_HOME}/bin/java.exe
AppParameters
=>-jar selenium-server-standalone-2.42.2.jar -role hub
AppDirectory
=>C:\tools\selenium
Application
=>${JAVA_HOME}/bin/java.exe
AppParameters
=>-jar selenium-server-standalone-2.42.2.jar -role hub
AppDirectory
=>C:\tools\selenium
Credit for this goes to http://codeforjava.blogspot.com/2010/12/run-java-application-as-windows-nt.html
这归功于http://codeforjava.blogspot.com/2010/12/run-java-application-as-windows-nt.html