简体   繁体   中英

Tomcat : java.net.ConnectException: Connection refused

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 ,

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.

How to fix this and shutdown my tomcat without bug ?

If its windows try below to kill the running tomcat process

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

ps -ef | grep "tomcat"
kill -9  <PID>

kill the running instance of tomcat, killing your java application wont kill tomcat

To get the running tomcat port use sudo netstat -lnp | grep <PID> sudo netstat -lnp | grep <PID>

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

Try changing the port number from 8005 to some other port number and restart Eclipse .

sometimes it may happen that the port number is blocked by sudden termination of process

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM