Terminating mvn spring-boot:run doesn't stop tomcat
Solution 1
It still happens to me on version 1.1.9 running on windows 7.
So after hitting Ctrl C. The fastest way to kill the background java will be .
Find the java PID
c:\>netstat -ano | find "8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 1196
TCP [::]:8080 [::]:0 LISTENING 1196
c:\>taskkill /F /PID 1196
SUCCESS: The process with PID 1196 has been terminated.
I am assuming in the example above that you are running on http port 8080
For Mac Users:
$lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java SOME_PID user 417u IPv6 0xa4b3be242c249a27 0t0 TCP *:name (LISTEN)
kill -9 SOME_PID
Solution 2
Here is what I do on Mac:
kill `lsof -i -n -P | grep TCP | grep 8080 | tr -s " " "\n" | sed -n 2p`
It finds the PID using 8080 and kills it.
Solution 3
Edit: in ubuntu, use the command:
fuser -k 8080/tcp
to kill the process. I'm using spring-boot 1.3.0-Build-snapshot and the problem still persist. My SO is Ubuntu and the problem occurs either running from Eclipse or from the console. The discussion about this issue is here. This seems to be an issue with spring-boot libraries, at least concerning tomcat libraries. I'm also in the line for the this fix. Unfortunately this is the price we pay for trying to use cutting edge technologies until they get matured.
Solution 4
For those using Eclipse, this is by far the best answer:
Open "run configurations", edit the maven launch you defined for your project, and under the "JRE" tab, add -Dfork=false to the VM arguments text area.
Then when you hit the red stop button, the tomcat server will stop and your ports will be released.
Answer comes from a post here on Github by jordihs
Solution 5
In IDEA you have to Stop process before Run it again. That command will shut down embedded Tomcat.
szxnyc
Software engineer, tinkerer, curious, musician, and all around nice guy. Appreciates the front-end limelight of Web Programming but prefers the good old catacombs of back-end Server Side Development.
Updated on February 04, 2022Comments
-
szxnyc over 2 years
I can successfully start spring-boot with
mvn spring-boot
, the documentation mentions to gracefully exit the application hitctrl-c
.Terminate batch job (Y/N)? Y
The maven process does terminate but Tomcat is still running and I can still hit the web-page. When I try to start spring-boot again it fails to start Tomcat because the port is in use.
. ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.1.0.BUILD-SNAPSHOT) 2014-05-02 12:13:57.666 INFO 6568 --- [ main] Example : Starting Example on challenger with PID 6568 (E:\workspace\SpringBoot\target\cla sses started by steven in E:\workspace\SpringBoot) 2014-05-02 12:13:57.707 INFO 6568 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWeb ApplicationContext@11ecab7c: startup date [Fri May 02 12:13:57 EDT 2014]; root of context hierarchy 2014-05-02 12:13:58.097 INFO 6568 --- [ main] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean : class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfi gure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class pat h resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; laz yInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAuto ConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfig ure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]] 2014-05-02 12:13:58.682 INFO 6568 --- [ main] .t.TomcatEmbeddedServletContainerFactory : Server initialized with port: 8080 2014-05-02 12:13:58.892 INFO 6568 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat 2014-05-02 12:13:58.892 INFO 6568 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/7.0.53 2014-05-02 12:13:58.981 INFO 6568 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2014-05-02 12:13:58.981 INFO 6568 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1277 ms 2014-05-02 12:13:59.453 INFO 6568 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/] 2014-05-02 12:13:59.455 INFO 6568 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2014-05-02 12:13:59.570 ERROR 6568 --- [ main] o.a.coyote.http11.Http11NioProtocol : Failed to start end point associated with ProtocolHandler ["http-nio-8080"] java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:344) at sun.nio.ch.Net.bind(Net.java:336) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473) at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:647) at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:449) at org.apache.catalina.connector.Connector.startInternal(Connector.java:1007) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:459) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:79) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:69) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:270) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:145) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:159) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:680) at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) at org.springframework.boot.SpringApplication.run(SpringApplication.java:941) at org.springframework.boot.SpringApplication.run(SpringApplication.java:930) at Example.main(Example.java:16) 2014-05-02 12:13:59.571 ERROR 6568 --- [ main] o.apache.catalina.core.StandardService : Failed to start connector [Connector[org.apache.coyote.http11.Http11NioProtocol- 8080]] org.apache.catalina.LifecycleException: Failed to start component [Connector[org.apache.coyote.http11.Http11NioProtocol-8080]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:459) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Tomcat.start(Tomcat.java:341) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:79) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:69) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:270) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:145) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:159) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:680) at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) at org.springframework.boot.SpringApplication.run(SpringApplication.java:941) at org.springframework.boot.SpringApplication.run(SpringApplication.java:930) at Example.main(Example.java:16) Caused by: org.apache.catalina.LifecycleException: service.getName(): "Tomcat"; Protocol handler start failed at org.apache.catalina.connector.Connector.startInternal(Connector.java:1014) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 18 common frames omitted Caused by: java.net.BindException: Address already in use: bind at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:344) at sun.nio.ch.Net.bind(Net.java:336) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:473) at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:647) at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:449) at org.apache.catalina.connector.Connector.startInternal(Connector.java:1007) ... 19 common frames omitted 2014-05-02 12:13:59.572 INFO 6568 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat 2014-05-02 12:13:59.580 INFO 6568 --- [ main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [file:/E:/workspace/SpringBoot/src/m ain/resources, file:/E:/workspace/SpringBoot/src/main/resources, file:/E:/workspace/SpringBoot/target/classes/, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring -boot-starter-web/1.1.0.BUILD-SNAPSHOT/spring-boot-starter-web-1.1.0.BUILD-SNAPSHOT.jar, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring-boot-starter/1.1.0.BUI LD-SNAPSHOT/spring-boot-starter-1.1.0.BUILD-SNAPSHOT.jar, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring-boot/1.1.0.BUILD-SNAPSHOT/spring-boot-1.1.0.BUILD-SNA PSHOT.jar, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.1.0.BUILD-SNAPSHOT/spring-boot-autoconfigure-1.1.0.BUILD-SNAPSHOT.jar, file:/C: /Users/steven/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.1.0.BUILD-SNAPSHOT/spring-boot-starter-logging-1.1.0.BUILD-SNAPSHOT.jar, file:/C:/Users/steven/. m2/repository/org/slf4j/jcl-over-slf4j/1.7.7/jcl-over-slf4j-1.7.7.jar, file:/C:/Users/steven/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar, file:/C:/Users/steven/.m2 /repository/org/slf4j/jul-to-slf4j/1.7.7/jul-to-slf4j-1.7.7.jar, file:/C:/Users/steven/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.7/log4j-over-slf4j-1.7.7.jar, file:/C:/Users/st even/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar, file:/C:/Users/steven/.m2/repository/ch/qos/logback/logback-core/1.1.2/logback-core-1.1.2.jar, f ile:/C:/Users/steven/.m2/repository/org/yaml/snakeyaml/1.13/snakeyaml-1.13.jar, file:/C:/Users/steven/.m2/repository/org/springframework/boot/spring-boot-starter-tomcat/1.1.0.BUILD -SNAPSHOT/spring-boot-starter-tomcat-1.1.0.BUILD-SNAPSHOT.jar, file:/C:/Users/steven/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/7.0.53/tomcat-embed-core-7.0.53.jar, f ile:/C:/Users/steven/.m2/repository/org/apache/tomcat/embed/tomcat-embed-el/7.0.53/tomcat-embed-el-7.0.53.jar, file:/C:/Users/steven/.m2/repository/org/apache/tomcat/embed/tomcat-e mbed-logging-juli/7.0.53/tomcat-embed-logging-juli-7.0.53.jar, file:/C:/Users/steven/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.3.3/jackson-databind-2.3.3.jar, fi le:/C:/Users/steven/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.3.0/jackson-annotations-2.3.0.jar, file:/C:/Users/steven/.m2/repository/com/fasterxml/jackson/co re/jackson-core/2.3.3/jackson-core-2.3.3.jar, file:/C:/Users/steven/.m2/repository/org/springframework/spring-web/4.0.3.RELEASE/spring-web-4.0.3.RELEASE.jar, file:/C:/Users/steven/ .m2/repository/org/springframework/spring-aop/4.0.3.RELEASE/spring-aop-4.0.3.RELEASE.jar, file:/C:/Users/steven/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar, file :/C:/Users/steven/.m2/repository/org/springframework/spring-beans/4.0.3.RELEASE/spring-beans-4.0.3.RELEASE.jar, file:/C:/Users/steven/.m2/repository/org/springframework/spring-cont ext/4.0.3.RELEASE/spring-context-4.0.3.RELEASE.jar, file:/C:/Users/steven/.m2/repository/org/springframework/spring-core/4.0.3.RELEASE/spring-core-4.0.3.RELEASE.jar, file:/C:/Users /steven/.m2/repository/org/springframework/spring-webmvc/4.0.3.RELEASE/spring-webmvc-4.0.3.RELEASE.jar, file:/C:/Users/steven/.m2/repository/org/springframework/spring-expression/4 .0.3.RELEASE/spring-expression-4.0.3.RELEASE.jar] Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedde d.EmbeddedServletContainerException: Unable to start embedded Tomcat at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:135) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:476) [INFO] ------------------------------------------------------------------------ at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:120) [INFO] BUILD SUCCESS at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:680) [INFO] ------------------------------------------------------------------------ at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) [INFO] Total time: 4.653 s at org.springframework.boot.SpringApplication.run(SpringApplication.java:941) at org.springframework.boot.SpringApplication.run(SpringApplication.java:930) at Example.main(Example.java:16) Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat [INFO] Finished at: 2014-05-02T12:13:59-05:00 at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:106) [INFO] Final Memory: 16M/232M [INFO] ------------------------------------------------------------------------ at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:69) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:270) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:145) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:159) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:132) ... 7 more Caused by: java.lang.IllegalStateException: Tomcat connector in failed state at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:102) ... 12 more
To proceed I have to manually terminate the running process. Is this a bug or am I missing something?
-
John M almost 10 yearsI'm at
1.1.4.BUILD-SNAPSHOT
and it is still present. What do you mean by "should be fixed"? -
Dave Syer almost 10 yearsI mean that issue was fixed (if you run from the cmd window in windows you can stop the build and the app with CTRL-C). If you are using Cygwin you might find that it is still a problem, but Cygwin is unique and I'm not sure it's possible to fix there.
-
raphinesse almost 10 yearsStill a problem when running out of Eclipse
-
Dave Syer almost 10 yearsRunning what out of eclipse? What did you do exactly?
-
dan carter almost 10 yearsRight click on project -> Run as -> Maven build. In goals put "spring-boot:run" Run the app. Now terminate it ( by the usual red stop button in the console view). Spring-boot process remains running.
-
Dave Syer almost 10 yearsI suggest you don't run Maven from inside Eclipse then. Just right click on the main class and Run As -> Java Application (or get STS and right click on project Run As -> Spring Boot Application).
-
Niko Bellic over 9 years@DaveSyer Thanks for that bit about Cygwin. I can confirm that this is still is a problem in Cygwin.
-
Dave Syer over 9 yearsIt always will be if you fork a process in Cygwin. The latest Boot releases 1.2.0 and up don't fork by default, but they have to fork if you are adding an agent.
-
Christof over 9 yearsUnder Mac: same issue as described by @dancarter. Had to manually kill the process ('ps -ef | grep javaagent').
-
Dave Syer over 9 yearsIt works for other people on a UN*X system (including Mac). Please open an issue in github if this isn't the case for you - make sure you are using the latest version.
-
e4c5 almost 9 yearsPerhaps this should be a comment instead?
-
benscabbia over 8 yearsIf you get an
Access Denied
message when runningtaskkill
make sure you are running cmd in Administrator mode -
thisdotnull over 8 yearsFow windows - stackoverflow.com/questions/6204003/…
-
Nailgun about 8 years@Buminda that is if your application server runs not as a background process which is often the case
-
Ankit about 7 yearseveryone will have different PID and not 3361.
-
FullStackDeveloper almost 7 years@gudthing Nice. I got 'Access Denied', then I run cmd in Admin mode, it works. I want to know if I kill the task (A) which uses that port, will this cause issue when this task (A) run later?
-
Abu Sulaiman over 6 yearsThis only works if you add the fork=false in the VM arguments. See my answer.
-
Kr1 over 5 yearsThis is actually the best solution
-
Tiemo Vorschütz almost 4 yearsHelped. Thanks. BTW: I was able to modify the PID. :-)