Question

I have to execute a compiled Java server through an ant task for an assignment so that I can build a client for it. I don't have the code of the server but it's supposed to run on the 8181 port of the localhost after being launched. It's working in windows and on other linux machines but I cannot run on this one (crunchbang). This is the error I get:

BUILD SUCCESSFUL
Total time: 1 second
root@drne:/home/wallen/uni/workspace/A5# ant run-server
Buildfile: /home/wallen/uni/workspace/A5/build.xml

setseed:

run-server:
     [java] Exception in thread "main" com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Cannot assign requested address
     [java]     at com.sun.xml.internal.ws.transport.http.server.ServerMgr.createContext(ServerMgr.java:102)
     [java]     at com.sun.xml.internal.ws.transport.http.server.HttpEndpoint.publish(HttpEndpoint.java:63)
     [java]     at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:171)
     [java]     at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:113)
     [java]     at javax.xml.ws.Endpoint.publish(Endpoint.java:240)
     [java]     at it.polito.dp2.PJS.lab5.PJSInfoServer.main(Unknown Source)
     [java] Caused by: java.net.BindException: Cannot assign requested address
     [java]     at sun.nio.ch.Net.bind0(Native Method)
     [java]     at sun.nio.ch.Net.bind(Net.java:344)
     [java]     at sun.nio.ch.Net.bind(Net.java:336)
     [java]     at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199)
     [java]     at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
     [java]     at sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:98)
     [java]     at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:50)
     [java]     at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:35)
     [java]     at com.sun.net.httpserver.HttpServer.create(HttpServer.java:129)
     [java]     at com.sun.xml.internal.ws.transport.http.server.ServerMgr.createContext(ServerMgr.java:84)
     [java]     ... 5 more
     [java] Java Result: 1

Things I've tried:

  • checking if there is another server running on that port
  • running it as su
Was it helpful?

Solution 2

I managed to fix what was giving me this error and as I supposed at the beginning of the matter it was not related to any java code: my loopback interface was weirdly down. ifconfig lo up did the trick.

OTHER TIPS

The answers to this question suggest that this may happen if the name "localhost" is not resolvable to an IP address. Check your /etc/hosts file and ensure that it has a mapping for localhost to the address 127.0.0.1.

Make sure you double check the server address you are deploying to. I had a misspelling on the server address and I got the exact same error...

I'm using the included web service libraries available in Java 6 & 7:

Endpoint.publish("http://myservername.com/myapi", new ServiceHandler(appSettings));

Double check the value for "myservername.com", this one is assuming port 80. If you have some other port (i.e. 8080) then the command would look like this:

Endpoint.publish("http://yourservername.com:8080/myapi", new ServiceHandler(appSettings));

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top