Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.net.BindException: Address already in use: bind in JDK1.6

 
Rahul Ba
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all

I have following program....

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.Endpoint;

@WebService
public class Calculator {

@WebMethod
public int add(int a, int b) {
return a+b;
}

public static void main(String[] args){
// create and publish an endpoint
Calculator calculator = new Calculator();
Endpoint endpoint = Endpoint.publish("http://localhost:8080/calculator", calculator);
}
}


then I ran
apt to compile and generate required wrapper classes

* apt -d sample com/Calculator.java

I got following warnings, but I ignored that:

warning: Annotation types without processors: [javax.xml.bind.annotation.XmlRoot
Element, javax.xml.bind.annotation.XmlAccessorType, javax.xml.bind.annotation.Xm
lType, javax.xml.bind.annotation.XmlElement]


then I triedd tp publish it by using following command

* java -cp sample com.Calculator

I got the following exception

Exception in thread "main" com.sun.xml.internal.ws.server.ServerRtException: Ser
ver Runtime Error: java.net.BindException: Address already in use: bind
at com.sun.xml.internal.ws.transport.http.server.ServerMgr.createContext
(Unknown Source)
at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(Un
known Source)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(Un
known Source)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(Unk
nown Source)
at javax.xml.ws.Endpoint.publish(Unknown Source)
at com.Calculator.main(Calculator.java:19)
Caused by: java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
at sun.net.httpserver.ServerImpl.<init>(Unknown Source)
at sun.net.httpserver.HttpServerImpl.<init>(Unknown Source)
at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(Unknown
Source)
at com.sun.net.httpserver.HttpServer.create(Unknown Source)
... 6 more


Please can you tell me what is the problem with my code as above.......
Thanks in advance.


 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
It looks like you already use port 8080 on your computer. Have you tried to publish the service to another port, for instance 8085?
Best wishes!

P.S. I tried the program and I got the same result as you, as far as using apt is concerned. The webservice does publish without any problems, though.
 
Rahul Ba
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yes, I tried with port 8085, but I am getting the same Address alreay bind exception. Any guess......
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic