File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes java.net.BindException: Address already in use: bind in JDK1.6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "java.net.BindException: Address already in use: bind in JDK1.6" Watch "java.net.BindException: Address already in use: bind in JDK1.6" New topic
Author

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

Rahul Ba
Ranch Hand

Joined: Oct 01, 2008
Posts: 203

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

Joined: Oct 04, 2006
Posts: 2198
    
    1
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

Joined: Oct 01, 2008
Posts: 203

Yes, I tried with port 8085, but I am getting the same Address alreay bind exception. Any guess......
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.net.BindException: Address already in use: bind in JDK1.6
 
Similar Threads
BindException
MD5
problem with stateful service
http://localhost:8080 is not opening
java.rmi.server.ExportException: Port already in use: 10344;