Tomcat:java.net.ConnectException:连接被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33448995/
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
Tomcat : java.net.ConnectException: Connection refused
提问by MMMMS
I am trying to shutdown and start my tomcat after i uploaded new war file. but i am getting Connection refused error while shutdown the tomcat instance. the error is below ,
上传新的war文件后,我试图关闭并启动我的tomcat。但是我在关闭 tomcat 实例时收到连接被拒绝的错误。错误如下,
Oct 31, 2015 2:55:44 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Could not contact localhost:8005. Tomcat may not be running.
Oct 31, 2015 2:55:44 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at java.net.Socket.<init>(Socket.java:434)
at java.net.Socket.<init>(Socket.java:211)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:498)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:370)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:457)
Tomcat stopped
Even i killed running java id using kill -9 PID but still i am getting same error and i can not start my application.
即使我使用 kill -9 PID 终止了运行 java id 但我仍然遇到相同的错误并且我无法启动我的应用程序。
How to fix this and shutdown my tomcat without bug ?
如何解决这个问题并在没有错误的情况下关闭我的 tomcat?
回答by Saravana
If its windows try below to kill the running tomcat process
如果它的窗口尝试在下面杀死正在运行的 tomcat 进程
C:\Users\Saravana.Saravana-PC>netstat -ano | find ":8080"
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 1448
TCP 127.0.0.1:8080 127.0.0.1:49543 ESTABLISHED 1448
TCP 127.0.0.1:49543 127.0.0.1:8080 ESTABLISHED 4068
TCP [::]:8080 [::]:0 LISTENING 1448
TCP [::1]:8080 [::1]:49542 ESTABLISHED 1448
TCP [::1]:49542 [::1]:8080 ESTABLISHED 4068
C:\Users\Saravana.Saravana-PC>taskkill.exe /PID 1448 /F
SUCCESS: The process with PID 1448 has been terminated.
C:\Users\Saravana.Saravana-PC>
In Linux if stopTomcat.sh
is not stopping tomcat then
在 Linux 中,如果stopTomcat.sh
不停止 tomcat 那么
ps -ef | grep "tomcat"
kill -9 <PID>
kill the running instance of tomcat, killing your java application wont kill tomcat
杀死tomcat的运行实例,杀死你的java应用程序不会杀死tomcat
To get the running tomcat port use sudo netstat -lnp | grep <PID>
要获取正在运行的 tomcat 端口,请使用 sudo netstat -lnp | grep <PID>
回答by NargesooTv
I cleaned my webapps and it helped me:
我清理了我的网络应用程序,它帮助了我:
cd /opt/tomcat/webapps
shopt -s extglob
rm -rf !(ROOT|balancer|webdav)
after that, I was able to deploy my application
之后,我能够部署我的应用程序
回答by Saketh Kotha
Try changing the port number from 8005 to some other port number and restart Eclipse .
尝试将端口号从 8005 更改为其他端口号并重新启动 Eclipse。
sometimes it may happen that the port number is blocked by sudden termination of process
有时可能会发生端口号因进程突然终止而被阻塞的情况