从 Eclipse 运行时如何杀死 Tomcat?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4341082/
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
How to kill Tomcat when running it from Eclipse?
提问by Carlos Sanchez
I am running the Tomcat that gets delivered with your Eclipse download (no, I don't want to download and install the entire Tomcat), and sometimes it hangs when stopping or restarting, and the only way I can find to make it work is restarting all my Eclipse. I am using it under Windows.
我正在运行随 Eclipse 下载一起提供的 Tomcat(不,我不想下载并安装整个 Tomcat),有时它在停止或重新启动时挂起,我能找到的唯一方法是让它工作重新启动我所有的 Eclipse。我在 Windows 下使用它。
Is there any way to kill the Tomcat process (which doesn't appear in the Task Manager)?
有没有办法杀死Tomcat进程(它没有出现在任务管理器中)?
回答by BalusC
It appears as javaw.exe
in task manager. An alternative is to execute Tomcat/bin/shutdown.bat
.
它出现javaw.exe
在任务管理器中。另一种方法是执行Tomcat/bin/shutdown.bat
.
As to the hang problem, are you sure that your webapp isn't spawning unmanaged threads which might be blocking Tomcat's shutdown?
至于挂起问题,您确定您的 web 应用程序没有产生可能阻止 Tomcat 关闭的非托管线程吗?
回答by Andrei Epure
On Windows, if you know the port Tomcat listens to (below, it is 8080), you can find the PID of the Tomcat process and then kill it from cmd:
在Windows上,如果你知道Tomcat监听的端口(下面是8080),你可以找到Tomcat进程的PID,然后从cmd中kill掉它:
> netstat -aon | find "8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 2196
TCP [::]:8080 [::]:0 LISTENING 2196
> taskkill /pid 2196 /f
SUCCESS: The process with PID 2196 has been terminated.
回答by shivadarshan
I use better way to shutdown tomcat when it is not found in task manager.
当在任务管理器中找不到时,我使用更好的方法关闭 tomcat。
1) Download TCPView(only 285kb)from following link.
1)从以下链接下载TCPView(仅 285kb)。
http://technet.microsoft.com/en-in/sysinternals/bb897437.aspx
http://technet.microsoft.com/en-in/sysinternals/bb897437.aspx
2) Extract folder and start TCPViewapplication.
2) 解压文件夹并启动TCPView应用程序。
3) Right click on java.exeand select End Processoption.
3) 右键单击java.exe并选择结束进程选项。
this would stop your tomcat easily.. This tool is very useful in monitoring port usage.
这将很容易停止你的 tomcat。这个工具在监控端口使用方面非常有用。
NOTE: Running TOMCATPATH/bin/shutdown.batmay not shutdown Tomcat when it contains some demon or unmanaged threads. In such cases TCPViewworks fine without any issues.
注意:运行TOMCATPATH/bin/shutdown.bat当 Tomcat 包含一些恶魔或非托管线程时,它可能不会关闭 Tomcat。在这种情况下,TCPView可以正常工作,没有任何问题。
回答by Alexander Pozdneev
If you use Linux, try the following steps.
如果您使用 Linux,请尝试以下步骤。
- List Tomcat processes (e.g.,
ps aux | grep catalina
) - Locate the strings that look like this:
myname 2244 5.5 0.3 57020937 2110741 ? Sl Oct03 5160:01 /usr/lib/jvm/java-1.8.0-<...>/bin/java <...> org.apache.catalina.startup.Bootstrap start
- Copy-paste everything between
/usr/lib/jvm/<...>
and<...>.Bootstrap
- Add
stop
at the end of your command and run it
- 列出 Tomcat 进程(例如,
ps aux | grep catalina
) - 找到如下所示的字符串:
myname 2244 5.5 0.3 57020937 2110741 ? Sl Oct03 5160:01 /usr/lib/jvm/java-1.8.0-<...>/bin/java <...> org.apache.catalina.startup.Bootstrap start
- 在
/usr/lib/jvm/<...>
和之间复制粘贴所有内容<...>.Bootstrap
stop
在命令末尾添加并运行它
Essentially, you would take the very same command that was used by Eclipse to start Tomcat and modify the last argument to stop Tomcat.
本质上,您将采用 Eclipse 用来启动 Tomcat 的相同命令并修改最后一个参数来停止 Tomcat。
回答by squaregoldfish
You can set a timeout on startup and shutdown for your Tomcat server in Eclipse. If these timeouts are exceeded, Eclipse will pop up a message asking you if you want to kill it, or keep waiting.
您可以在 Eclipse 中为 Tomcat 服务器设置启动和关闭超时。如果超过这些超时时间,Eclipse 会弹出一条消息,询问您是要杀死它还是继续等待。
To set these, double-click the name of the server in your Servers tab. It'll open a window like this:
要设置这些,请在“服务器”选项卡中双击服务器的名称。它会打开一个这样的窗口:
There's a Timeouts section on the right hand side. I set startup to a day (so I can debug startup without it timing out), and shutdown to 30 seconds to be generous (usually this can be very short, since most apps can survive a forced shutdown with no issues).
右侧有一个超时部分。我将启动设置为一天(因此我可以在不超时的情况下调试启动),并将关闭时间设置为 30 秒(通常这可能很短,因为大多数应用程序可以在强制关闭的情况下正常运行)。