how to make jetty server accessible from LAN?

Sami picture Sami · Aug 4, 2012 · Viewed 32.1k times · Source

I am trying to access a web app (deployed in jetty8 on my machine (A)) from another machine (B) on the LAN using 192.168.0.6:8080 (A's IP) but its not working. While I can access apps hosted on AppServ on machine B from A normally using 192.168.0.5 (B's IP).

I can access the app normally on localhost:8080 on machine A.

I can assure that there is no network problem, but jetty is not accessible through the network for some reason. Is there any specific configuration to make accessible through the LAN?

My app is Maven project and I run it from eclipse and settings are in both web.xml and pom.xml.

Answer

Joakim Erdfelt picture Joakim Erdfelt · Aug 10, 2012

The following answer is for Jetty 8 and older (Jetty 9+ commands and class names are different)

Make sure you check what interfaces you are listening on.

Example (from logs)

2012-08-10 14:52:26.470:INFO:oejs.AbstractConnector:Started [email protected]:8080

That says the server is only listening on 127.0.0.1 (localhost) You can either look at the logs, or just do a quick test, while on machine A. Open a web browser and test both of these URLs

  • http://localhost:8080/
  • http://192.168.0.6:8080/

If it responds on both URLs then you likely have it setup correctly and need to deal with firewall issues. If it works for one, but not the other, then you are only listening on 1 interface.

To have jetty listen on all interfaces, use the special IP 0.0.0.0

$ java -Djetty.host=0.0.0.0 -jar start.jar
2012-08-10 14:53:25.338:INFO:oejs.AbstractConnector:Started [email protected]:8080

At this point, jetty is listening on all interfaces on your machine.

Note: you can also edit etc/jetty.xml and set the host permanently.

      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host">0.0.0.0</Set>
      ...