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
So I hit this and after an afternoon of debugging odd behaviours, I discovered Jetty was only broadcasting itself to IPv6, and skipping IPv4, the v4 port was allocated to another app.
My solution? Jump to another port...
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 SelectChannelConnector@127.0.0.1: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 SelectChannelConnector@0.0.0.0: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>
...
2020-07-20
As an addition to @JoakimErdfelt answer, on Jetty 9.4.12.v20180830 (and above), you can configure the host programatically as:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
Server server = new Server();
ServerConnector httpConnector = new ServerConnector(server);
httpConnector.setHost("0.0.0.0"); // <--------- !
httpConnector.setPort(12345);
httpConnector.setIdleTimeout(5000);
server.addConnector(httpConnector);