how to make jetty server accessible from LAN?

北城以北 提交于 2019-11-28 12:01:54

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>
      ...

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...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!