Java 无法将 Tomcat 作为 Windows 服务启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24647003/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 13:42:44  来源:igfitidea点击:

Can't start Tomcat as Windows Service

javawindowstomcatwindows-services

提问by melo

I am using Tomcat6 on Windows 8. I am able to start Tomcat via startup.bat without error. I've copied Tomcat6.exe, Tomcat6w.exe and service.bat under tomcat/bin directory and set the .exe files to run as administrator.

我在 Windows 8 上使用 Tomcat6。我可以通过 startup.bat 启动 Tomcat,没有错误。我已将Tomcat6.exe、Tomcat6w.exe 和service.bat 复制到tomcat/bin 目录下,并将.exe 文件设置为以管理员身份运行。

I open command line with administrator rights and execute "service.bat install" which ran without error. In Windows Services, I can see Apache Tomcat 6 which I want to run automatically.

我以管理员权限打开命令行并执行“service.bat install”,它运行没有错误。在 Windows 服务中,我可以看到我想自动运行的 Apache Tomcat 6。

But both running from Windows Services using "Start" button and on start up of Windows I got the same error.

但是,无论是使用“开始”按钮从 Windows 服务运行还是在启动 Windows 时,我都遇到了同样的错误。

"Windows could not start the Apache Tomcat 6 on Local Computer. For more information, review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 0.

“Windows 无法在本地计算机上启动 Apache Tomcat 6。有关详细信息,请查看系统事件日志。如果这是非 Microsoft 服务,请联系服务供应商,并参考特定于服务的错误代码 0。

When I check Windows Event Log, I see the following bizarre error.

当我检查 Windows 事件日志时,我看到以下奇怪的错误。

"Apache Tomcat 6 service terminated with the following service-specific error: The operation completed successfully."

“Apache Tomcat 6 服务因以下特定于服务的错误而终止:操作成功完成。”

I tried copying msvcr71.dll under tomcat/bin directory, but nothing changed. What else can I do?

我尝试将 msvcr71.dll 复制到 tomcat/bin 目录下,但没有任何改变。我还可以做些什么?

Update:

更新:

I am using a different port than 8080. And I saw the error below in the log file /logs/jakarta_service.log:

我使用的端口与 8080 不同。我在日志文件 /logs/jakarta_service.log 中看到以下错误:

%1 is not a valid Win32 application.

%1 不是有效的 Win32 应用程序。

回答by Anup Ganatra

You need to check the ports first. It might be situation that default port(8080) is used by some other application.

您需要先检查端口。可能是其他应用程序使用默认端口(8080)的情况。

Try changing the port from 8080 to some different port in conf/server.xml file.

尝试将端口从 8080 更改为 conf/server.xml 文件中的某个不同端口。

Also please check that your JRE_HOME variable is set correctly because tomcat needs JRE to run. You can also set your JRE_HOME variable in system. For that go to my computer->right click and select properties->Advanced system settings->Advanced->Environment variable and click on new-> variable name = "JRE_HOME" and variable value = "C:\Program Files\Java\jre7"

另外请检查您的 JRE_HOME 变量是否设置正确,因为 tomcat 需要 JRE 才能运行。您还可以在系统中设置 JRE_HOME 变量。为此,请转到我的计算机-> 右键单击​​并选择属性-> 高级系统设置-> 高级-> 环境变量并单击新建-> 变量名称 = "JRE_HOME" 和变量值 = "C:\Program Files\Java\ jre7"

回答by KingQQ

  1. Check the apache tomcat catalina log: ../logs/catalina.log
  2. If in the log you find the "port was used" exception, then Check windows used ports and processes with following command: Run cmd netstat -ao it will list all listening ports and corresponding process Id, you can find the port which was used by Tomcat from the configuration file: ../conf/server.xml

    <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
    
  1. 检查 apache tomcat catalina 日志:../logs/catalina.log
  2. 如果在日志中发现“端口已使用”异常,则使用以下命令检查 windows 使用的端口和进程:运行 cmd netstat -ao 它将列出所有侦听端口和相应的进程 ID,您可以找到被使用的端口Tomcat 来自配置文件:../conf/server.xml

    <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
    

and kill the process which use the tomcat port

并杀死使用tomcat端口的进程

回答by Nivedita Gopal

"Windows could not start the Apache Tomcat 6 on Local Computer. For more information, review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 0"

“Windows 无法在本地计算机上启动 Apache Tomcat 6。有关详细信息,请查看系统事件日志。如果这是非 Microsoft 服务,请联系服务供应商,并参考特定于服务的错误代码 0”

When an error of this sort come. please go to start -> configure tomcat -> startup -> Mode -> java similarly start -> configure tomcat -> shutdown -> Mode -> java

当出现这种错误时。请进入开始->配置tomcat->启动->模式->java同样启动->配置tomcat->关机->模式->java

回答by Prashant

Go to Start > Configure Tomcat >

转到开始 > 配置 Tomcat >

  • Startup > Mode = Java
  • Shutdown > Mode = Java
  • 启动 > 模式 = Java
  • 关机 > 模式 = Java

This worked for me!

这对我有用!

回答by Nitin Mestry

I had the similar issue, But installing tomcat 32bit and jdk 32 bit worked, This happens mostly because of mismatch Bit.

我有类似的问题,但安装 tomcat 32 位和 jdk 32 位工作,这主要是因为位不匹配。

回答by elin

I have the problem because I updated Java version.

我有问题,因为我更新了 Java 版本。

The following steps work for me:

以下步骤对我有用:

  1. Run \Tomcat\bin\tomcat7w.exe
  2. Confirm "Startup" tab -> "Mode" choose "jvm"
  3. "Java" tab -> update "Java Virtual Machine" path to new version path
  4. Restart Tomcat
  1. \Tomcat\bin\tomcat7w.exe
  2. 确认“启动”选项卡->“模式”选择“jvm”
  3. “Java”选项卡 -> 将“Java 虚拟机”路径更新为新版本路径
  4. 重启Tomcat

Done.

完毕。

回答by Comm4nd0

In my case it helps if you don't install the x86 version over the x64 version... DOH!!!

在我的情况下,如果您不在 x64 版本上安装 x86 版本,它会有所帮助... DOH!

回答by Hoque MD Zahidul

Cause :

原因 :

This issue is caused:

这个问题是由:

1- tomcat can't find the jvm file from the directory specified to start the service because is deleted.

2- Incorrect permissions to the java folder for read&write access

3- Incorrect JAVA_HOME path.

4- Antivirus deleted the jvm file from java folder

Resolution:

解析度:

1- confirm that especified file exisit in the java directoy.

2- Make sure that file has read&write permissions.

3- Confirm that JAVA_HOME is correct for java version.

4- if file has been deleted reinstall same java version to recreate missing files.

1- 确认指定的文件存在于 java 目录中。

2- 确保该文件具有读写权限。

3- 确认 JAVA_HOME 对于 java 版本是正确的。

4- 如果文件已被删除,重新安装相同的 Java 版本以重新创建丢失的文件。

回答by Zack Zilic

All those mistakes are related to badly connected Apache and JDK.

所有这些错误都与 Apache 和 JDK 连接不良有关。

  1. go to start>System>Advanced_system_settings>
  2. System Properties will pop-up go to Environment Variables
  3. in User variables you have to set variable: JAVA_HOME value: C:\Program_Files\Java\jdk1.8.0_161
  4. in System variables you need to put in the path: jdk/bin path & jre/bin path and also you need to have JAVA_HOME C:\Program_Files\Java\jdk1.8.0_161
  1. 转到开始>系统>Advanced_system_settings>
  2. 系统属性将弹出到环境变量
  3. 在用户变量中,您必须设置变量:JAVA_HOME 值:C:\Program_Files\Java\jdk1.8.0_161
  4. 在系统变量中,您需要放入路径:jdk/bin path & jre/bin path 并且您还需要有 JAVA_HOME C:\Program_Files\Java\jdk1.8.0_161

people usually forget to setup JAVA_HOME in System variables.

人们通常忘记在系统变量中设置 JAVA_HOME。

if you still have an error try to think step by step

如果你仍然有错误尝试一步一步思考

  1. Open Event viewer>Check Administrative Events and Windows Logs>System see the error. If that doesn't help
  2. go to C:\Program Files\Apache Software Foundation\Tomcat 7.0\logs commons-daemon.XXXX-XX-XX.log and READ THE ERRORS AND WARNINGS... there should be nicely put down in words what's the problem.
  1. 打开事件查看器>检查管理事件和 Windows 日志>系统查看错误。如果这没有帮助
  2. 转到 C:\Program Files\Apache Software Foundation\Tomcat 7.0\logs commons-daemon.XXXX-XX-XX.log 并阅读错误和警告......应该很好地用文字说明问题所在。

回答by ReL

The simplest answer that worked for me was the one mentioned by Prashant, and edited by Bluish.

对我有用的最简单的答案是 Prashant 提到的,由 Bluish 编辑的。

Go to Start > Configure Tomcat > Startup > Mode = Java Shutdown > Mode = Java

转到开始 > 配置 Tomcat > 启动 > 模式 = Java 关机 > 模式 = Java

Unfortunately I had(and possibly others) to do this in a different way, I went to the tomcat bin directory and ran the "tomcat7w" application, which is how I changed the configuration.

不幸的是,我(可能还有其他人)以不同的方式执行此操作,我转到 tomcat bin 目录并运行“tomcat7w”应用程序,这就是我更改配置的方式。

There I was able to change the startup mode and shutdown mode to Java. Like this:

在那里我能够将启动模式和关闭模式更改为Java。像这样:

Step1) Locate tomcat7w:

Step1) 找到 tomcat7w

general location => %TomCatHomeDIR%/binIn my case tomcat was in the xampp folder so my address was:

一般位置 => %TomCatHomeDIR%/bin在我的例子中,tomcat 在 xampp 文件夹中,所以我的地址是:

C:\xampp\tomcat\bin

C:\xampp\tomcat\bin

tomcat7w file location screenshot

tomcat7w 文件位置截图

Step2) Launch tomcat7w&& change the Mode in the Startup and Shutdown tabs

Step2) 启动tomcat7w&& 更改启动和关机选项卡中的模式

tomcat7w startup tab screenshot

tomcat7w 启动选项卡截图

Note >This based on version 7.0.22 that comes standard with XAMPP.

注意 >这基于 XAMPP 标准的 7.0.22 版。