How to solve Address or Port already in use error in java?

How to solve Address or Port already in use error in java? Address already in use: JVM Bind is one of the most popular error among java developers and guys who do socket

programming in some other language too. But with respect to java this error is much familiar with socket programming and during web development. This error

happens for ports 80 (HTTP) , 1098 (RMI) when it is used by other applications that is running on the same PC or server. So I am going to explain how to debug and solve this problem.

Step I : Finding the ports that are in use:

1. You can use the tool CurrPorts to solve this problem. You can google about the tool. How to find open ports in your PC?

2. If you are using windows XP you can use the netstat command to view which processing is occupying the port. If you use Windows 2000 then you cannot use the ‘ netstat -o ‘ in your netstat command which tells you the process ID that is using the port. So in windows 2000 use the tool CurrPorts which is free.

eg) netstat -ano


If you have problem with port 1098 then check whether outlook or firefox is currently in use and close the same to free the port. This is just an example and for a better report you can use the tools mentioned above.

Step II : Free up the port:

You can free up the port by 3 ways,

1. If you use CurrPorts tool then you can find the application that is using it and you can close it down or kill the process by right clicking in the tool.

2. In windows you can use the command ‘ taskkill /PID 828 ‘ to kill the appropriate process.

3. Making your program to use a different port. For instance if you are encountering this error with JBOSS Application server for port 80, then you can go to server.xml in the appropriate directory say server/default/deploy/jbossweb-tomcatXX.sar/server.xml and change the port to 8080 to avoid the conflict. In case of Tomcat look for server.xml in the conf directory

Hope the above explanation helps. Feel free to comment.


Post a Comment

Popular Posts