Friday, April 6, 2012

How to get rid of "Address already in use: JVM_Bind" in windows OR linux

You may get below errors in your server console on your server startup.

SEVERE: Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"] Address already in use: JVM_Bind :8080
 at org.apache.coyote.AbstractProtocolHandler.init(
 at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(
 at org.apache.catalina.connector.Connector.initInternal(
 at org.apache.catalina.util.LifecycleBase.init(
 at org.apache.catalina.core.StandardService.initInternal(
 at org.apache.catalina.util.LifecycleBase.init(
 at org.apache.catalina.core.StandardServer.initInternal(
 at org.apache.catalina.util.LifecycleBase.init(
 at org.apache.catalina.startup.Catalina.load(
 at org.apache.catalina.startup.Catalina.load(
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Caused by: Address already in use: JVM_Bind
 at Method)
 at Source)
 at Source)
 at Source)
 at Source)
 ... 17 more

As the error suggest there is already another server running on the same port (in our case 8080) . you can either kill that service or change your web server to run on another port.

1. How to kill previous service.

If you have decided to kill the previous service, then you just have to find the process in which your service is running and simpily kill that process.

Below are the commands to find the process and kill it.

 Window :

 In windows netstat is used to Displays protocol statistics and current TCP/IP network connections. Just find the process which is using the port number. Lets assume the process number is 6324. Then use taskkill command to forcefully terminate that process.

  • netstat -ano | find "8080"
  • taskkill /F /PID 6324

Linux :

Similarly in Linux we can use netstat command to find the process. In linux netstat is used to show network status and grep command is used to find the particular port out of it as shown below. Then use kill command to terminate the process.

  • netstat -an | grep "8080"
  • kill - 6324

2. How to change web server to run on another port.


If you are using tomcat, Just locate the file server.xml (E.g. C:/apache-tomcat-7.0.11/conf/server.xml). You will see below code snippet.

<Connector port="8080" protocol="HTTP/1.1"
               redirectPort="8443" />

Just change the above port number (E.g. 8080 ) to any other port number. Now your web server will run on the new port which you have provided.

Conclusion :

To get rid of "Address already in use: JVM_Bind" you can either kill that service or change your web server to run on another port.