Java Apache tomcat7 作为 windows 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21100451/
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
Apache tomcat7 as windows service
提问by selson
I am trying to create a windows service for Apache tomcat 7.0.45. ( in windows version 7)
我正在尝试为 Apache tomcat 7.0.45 创建 Windows 服务。(在 Windows 版本 7 中)
I executed this :
我执行了这个:
C:/tomcat7/bin> service install Mytomcat7
Windows service has been created. but it wont start and throws "specific server error code 4".
Windows 服务已创建。但它不会启动并抛出“特定服务器错误代码 4”。
Can you please help with the steps to create windows service.
您能否帮助创建 Windows 服务的步骤。
采纳答案by Dudelilama
I had the same problem!
我有同样的问题!
Found out, that the service.bat didn't configure the service the right way. If you enable the logging from your service starter:
发现 service.bat 没有以正确的方式配置服务。如果您从服务启动器启用日志记录:
Then you'll see in your loggs something like:
然后你会在你的日志中看到类似的东西:
[2014-02-19 16:40:35] [error] ( javajni.c:863 ) [ 2636] FindClass org/apache/catalina/startup/Bootstrap failed
[2014-02-19 16:40:35] [debug] ( javajni.c:964 ) [ 2636] Java Worker thread finished org/apache/catalina/startup/Bootstrap:main with status=3
[2014-02-19 16:40:35] [error] ( prunsrv.c:1183) [ 5000] Failed to start Java
[2014-02-19 16:40:35] [error] ( prunsrv.c:1536) [ 5000] ServiceStart returned 4
You'll notice that there is some classpath problem with the starter. In fact that's the problem! Your service.bat didn't configure the service the right way:
您会注意到 starter 存在一些类路径问题。事实上这就是问题所在!您的 service.bat 没有以正确的方式配置服务:
Note: You can also choose "Use default" above "Java Virtual Machine" to use whatever JVM is defined in JAVA_HOME
注意:您还可以选择“Java 虚拟机”上方的“使用默认值”以使用 JAVA_HOME 中定义的任何 JVM
You'll need to set the classpath correctly:
您需要正确设置类路径:
c:\webclient\apache-tomcat\bin\tomcat-juli.jar;c:\webclient\apache-tomcat\bin\tomcat-juli.jar;c:\webclient\apache-tomcat\bin\bootstrap.jar
c:\webclient\apache-tomcat\bin\tomcat-juli.jar;c:\webclient\apache-tomcat\bin\tomcat-juli.jar;c:\webclient\apache-tomcat\bin\bootstrap.jar
In my case i "installed" tomcat at: c:\webclient\apache-tomcat replace that part with yours. In my case not even the Java VM was set.. I'm not shure whether this is a problem with the current versions of tomcat (and it's service.bat), or with some sort of permission problem on the windows server itself..
就我而言,我在以下位置“安装”了 tomcat:c:\webclient\apache-tomcat 用您的替换该部分。在我的情况下,甚至没有设置 Java VM .. 我不确定这是否是当前版本的 tomcat(以及它的 service.bat)的问题,还是 Windows 服务器本身的某种权限问题。
回答by Dror Bereznitsky
To solve this error perform the following steps:
要解决此错误,请执行以下步骤:
- Run the tomcat7w.exemonitor application found in
<TOMCAT_HOME>/bin
.
Tomcat7w is a GUI application for monitoring and configuring Tomcat services.
If you named your service Mytomcat7you will need to rename this file to Mytomcat7.exebefore running it - In the "Startup" tab change the value of "Mode" from jvmto Java
- Do the same in the "Shutdown" tab
- 运行tomcat7w.exe中发现的监视器应用程序
<TOMCAT_HOME>/bin
。
Tomcat7w 是一个用于监控和配置 Tomcat 服务的 GUI 应用程序。
如果您将服务命名为Mytomcat7,则需要在运行之前将此文件重命名为Mytomcat7.exe - 在“启动”选项卡中,将“模式”的值从jvm更改为Java
- 在“关机”选项卡中执行相同操作
回答by JayTee
The easiest way to setup a tomcat Windows service is to use the Tomcat Windows Service Installer found on the same page as tomcat downloads.
设置 tomcat Windows 服务的最简单方法是使用与 tomcat 下载位于同一页面上的 Tomcat Windows 服务安装程序。
http://tomcat.apache.org/download-70.cgi
http://tomcat.apache.org/download-70.cgi
However, if you are unable to use this installer. Then you can as you have try the above. The service created 'Mytomcat7' can be managed by the tomcat7w.exe file, after you rename it to 'Mytomcat7w.exe'.
但是,如果您无法使用此安装程序。然后你可以像上面那样尝试。创建的服务“Mytomcat7”可以通过 tomcat7w.exe 文件进行管理,将其重命名为“Mytomcat7w.exe”。
Run the renamed file and you will be able to see all options for the service. The error you are seeing is likely related to an invalid JVM location or JVM mode not set to auto. Details of settings found here: http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html
运行重命名的文件,您将能够看到该服务的所有选项。您看到的错误可能与无效的 JVM 位置或未设置为自动的 JVM 模式有关。此处设置的详细信息:http: //tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html
I would just use the installer, it will make your life easier. http://mirror.ox.ac.uk/sites/rsync.apache.org/tomcat/tomcat-7/v7.0.50/bin/apache-tomcat-7.0.50.exe
我只会使用安装程序,它会让您的生活更轻松。 http://mirror.ox.ac.uk/sites/rsync.apache.org/tomcat/tomcat-7/v7.0.50/bin/apache-tomcat-7.0.50.exe