Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make jetty server accessible from LAN?

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.

like image 444
Sami Avatar asked Aug 04 '12 10:08

Sami


2 Answers

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>
      ...
like image 176
Joakim Erdfelt Avatar answered Oct 16 '22 01:10

Joakim Erdfelt


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);
like image 22
Z3d4s Avatar answered Oct 16 '22 02:10

Z3d4s