How to kill Tomcat when running it from Eclipse?

64,821

Solution 1

It appears as javaw.exe in task manager. An alternative is to execute 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?

Solution 2

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:

> 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.

Solution 3

I use better way to shutdown tomcat when it is not found in task manager.

1) Download TCPView(only 285kb) from following link.

http://technet.microsoft.com/en-in/sysinternals/bb897437.aspx

2) Extract folder and start TCPView application.

3) Right click on java.exe and select End Process option.

this would stop your tomcat easily.. This tool is very useful in monitoring port usage.

NOTE: Running TOMCATPATH/bin/shutdown.bat may not shutdown Tomcat when it contains some demon or unmanaged threads. In such cases TCPView works fine without any issues.

Solution 4

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.

To set these, double-click the name of the server in your Servers tab. It'll open a window like this:

Eclipse Tomcat settings

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).

Solution 5

If you use Linux, try the following steps.

  1. List Tomcat processes (e.g., ps aux | grep catalina)
  2. 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
  3. Copy-paste everything between /usr/lib/jvm/<...> and <...>.Bootstrap
  4. Add stop at the end of your command and run it

Essentially, you would take the very same command that was used by Eclipse to start Tomcat and modify the last argument to stop Tomcat.

Share:
64,821
Carlos Sanchez
Author by

Carlos Sanchez

Updated on February 15, 2020

Comments

  • Carlos Sanchez
    Carlos Sanchez about 4 years

    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.

    Is there any way to kill the Tomcat process (which doesn't appear in the Task Manager)?

  • Carlos Sanchez
    Carlos Sanchez over 13 years
    no, i had'nt check if my webapp is spawning unmanaged threads. thank you.
  • doABarrelRoll721
    doABarrelRoll721 over 8 years
    Downloading additional Software should always be the very last resort. However, this answer contains the vital information that the shutdown.bat may not shutdown Tomcat properly.
  • shivadarshan
    shivadarshan over 8 years
    @doABarrelRoll721 thank you, ya i do accept it in case of production environment, but installing it in local system doesn't have considerable impact. Also i hope this method is simple and better way to solve.
  • mannedear
    mannedear over 5 years
    how do i check if my webapp isn't spawning unmanaged threads which might be blocking Tomcat's shutdown ?
  • squaregoldfish
    squaregoldfish about 5 years
    Of course, if your app is spawning unmanaged threads, which seems to have been the OP's issue, that's something to be detected and cleaned up anyway. The above is just a neat way to have Eclipse time out to prevent you having to wait for eternity.