Category Archives: Tomcat

Window : How to Kill/Stop tomcat service from command line?


Generally, when run tomcat by eclipse or use embedded tomcat with spring and suddenly close eclipse. But in background tomcat is running. When you try to run tomcat again you will face below exception:

[Solved] Tomcat : java.net.BindException: Address already in use: bind

Solutions

There are two ways to kill tomcat process:

  • Manually kill tomcat process from command line
  • Create script to kill tomcat processes

Manually  kill Tomcat Process from Command line

  1. Go to (Open) Command Prompt (Press Window + R then type cmd Run this).
  2. Run following commands to get all listening ports (If tomcat runnig on other ports apart from 8080)

netstat -aon | find /i "listening"

Apply port filter If you know port number


netstat -aon |find /i "listening" |find "8080"

As in below screen you will get PID and then  run the following command to kill the process

3 Copy PID from result set


taskkill /F /PID

Ex: taskkill /F /PID 13332

Kill Tomcat process from command line

Steps to kill Tomcat Process by script

  • Step 1: Copy below script in note pad and save it with extension as .bat

@ECHO OFF
netstat -aon |find /i "listening"

SET killPORT=
SET /P killPORT=Enter port: 
IF "%killPORT%"=="" GOTO Kill

netstat -aon |find /i "listening" | find "%killPORT%"

:Kill
SET killPID=
SET /P killPID=Enter PID to kill: 
IF "%killPID%"=="" GOTO Error

ECHO Killing %killPID%!
taskkill /F /PID %killPID%

GOTO End
:Error
ECHO No Process to kill!
:End

pause
  • Steps 2: Click  on saved batch file you will get list of all running processes on ports.
  • Step 3: Enter port which you want to kill. Script will return PID for same .
  • Step 4: Enter PID which you want to kill then your tomcat will stop.

Kill Tomcat process by script

Advertisements

[Solved] Tomcat : java.net.BindException: Address already in use: bind


This is exception occurs when using port for tomcat server is already used and not closed yet.

Sometimes when eclipse hang and you directly close eclipse by task manager then eclipse close but tomcat process still running. When you open Eclipse again and try to run tomcat to deploy application. On that time you will get below exception as “java.net.BindException: Address already in use“.

Problem

org.apache.catalina.LifecycleException: Failed to start component [Connector[HTTP/1.1-8080]]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
	at org.apache.catalina.core.StandardService.addConnector(StandardService.java:225) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.addPreviouslyRemovedConnectors(TomcatWebServer.java:256) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.start(TomcatWebServer.java:198) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.startWebServer(ServletWebServerApplicationContext.java:300) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:162) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) [spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE]
	at com.fiot.controller.Example.main(Example.java:17) [classes/:na]
Caused by: org.apache.catalina.LifecycleException: Protocol handler start failed
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1020) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
	... 13 common frames omitted
Caused by: java.net.BindException: Address already in use: bind
	at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_151]
	at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_151]
	at sun.nio.ch.Net.bind(Unknown Source) ~[na:1.8.0_151]
	at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source) ~[na:1.8.0_151]
	at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source) ~[na:1.8.0_151]
	at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
	at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:1150) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
	at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:591) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
	at org.apache.catalina.connector.Connector.startInternal(Connector.java:1018) ~[tomcat-embed-core-8.5.31.jar:8.5.31]
	... 14 common frames omitted

2018-05-28 15:36:23.875  INFO 12964 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-05-28 15:36:23.898  INFO 12964 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-05-28 15:36:23.900 ERROR 12964 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

Solutions

Please follow below steps to resolve this issue.

Window

  • Got to (Open) Command Prompt (Press Window +R) or type cmd on run.
  • Get running process for port on command prompt.

netstat -aon |find /i “listening” |find “PortNumber

  • Kill Process running for port.

taskkill /F /PID ProcessNumber