Main Tutorials

JAX-WS – java.net.BindException: Address already in use: bind

Developing a Java web service development with JAX-WS, and publish an end point…


public static void main(String[] args) {
   Endpoint.publish("http://localhost:8080/ws/hello", new WallStreetImpl());
}

1. Problem

It hits the following error message.


Exception in thread "main" com.sun.xml.internal.ws.server.ServerRtException: 
	Server Runtime Error: java.net.BindException: Address already in use: bind
	...
Caused by: java.net.BindException: Address already in use: bind
	at sun.nio.ch.Net.bind(Native Method)
	...

2. Solution

A very common error message, it means the address (usually it is the port number) is already in used by another application.

To fix it, change the end point port number :


public static void main(String[] args) {
   Endpoint.publish("http://localhost:1234/ws/hello", new WallStreetImpl());
}

Reference

  1. Linux – Which application is using port 8080

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
11 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
ved
6 years ago

In windows

c:/>netstat -ano

will list all the protocols, ports and processes listening . check on which port you deploy your service and then Use-

c:/>taskkill -pid “proces to kill” /f

to kill the process listening to the port. e.g
e.g.:
c:/> taskkill -pid 431 /f

dhaval
10 years ago

Thanks dude.problem solved.

Neeraj
2 years ago

Seems like its port already occupied issue. Did any of you guys faced this issue on teamcity/jenkins/bamboo where mutliple people pushed code in their respective feature branches but their Junits using same port number (as it is defined in code) and then each branch is getting build and trying to use same port?

Prathap
10 years ago

Hi,

I am able to fix this error if we change the port address.

My problem is:

I have published a web service at say http://localhost:8085/ws/hello successfully,
i have added two more methods to the web service implementation class and i would like to publish the web service(update) to the same location.

how can i publish the updated web services to the previous url?

Please help me. Quick help would be appreciated.

but i would like to keep the same port for the updated web service.

xanaduboi
9 years ago
Reply to  Prathap

1. You do a “netstat -ao” in the command prompt to check for the PID of the published web service.
2. Kill the process using “taskkill /PID /F”

It should free the port.

xanaduboi
9 years ago
Reply to  xanaduboi

taskkill /PID /F

Gaja
10 years ago

So if I want to free that port. What I have to do? Could you please advice.

Name
11 years ago

AWSOME DUDE!

Gaurav Arora
11 years ago

Always a savior, Thanks Mr MkYong

june
11 years ago

really cool and thanks Mr MkYong

Sri
11 years ago

Thank you. Changed the port from 8080 to 8081 and it worked 🙂