14

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.

Sami
  • 7,797
  • 18
  • 45
  • 69
  • how do you start jetty exactly? within eclipse, or with mvn jetty:run? – Stefan Ferstl Aug 04 '12 at 12:38
  • @StefanFerstl I have added mvn jetty:run to eclipse run configuration. So I can run the project from eclipse and eclipse will run jetty. then I can access the app locally on localhost:8080/appName – Sami Aug 04 '12 at 12:51
  • 1
    What is OS you are running on? Do you have any firewall settings that might prevent visibility of the ports? – Edmon Aug 04 '12 at 13:45
  • @Edmon I have windows7 .. I switched off windows firewall but it did not work. – Sami Aug 04 '12 at 14:01
  • I could not reproduce your problem on Win7. Could you look at the "Network and sharing center" if the firewall is really turned off? – Stefan Ferstl Aug 05 '12 at 20:36
  • @StefanFerstl yes, its turned off. – Sami Aug 06 '12 at 10:18
  • I am also getting the same issue with embedded jetty. We have the application (with embedded jetty) running on an Ubuntu Server (cloud VM). We can access the application from the same VM using http://localhost:8080. But when I try to access it over internet using the public IP of the system, it doesn’t work. My network and firewall setup are proper as I can access other applications deployed in tomcat in the same machine. I have tested with 8080 port in tomcat as well. – spideringweb May 23 '16 at 16:35

3 Answers3

18

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>
      ...
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • 2
    I could only access `http://localhost:8080`. I used `mvn jetty:run -Djetty.host=0.0.0.0` to run jetty and it run and got the log you mentioned `SelectChannelConnector@0.0.0.0:8080`. But still can't access `http://192.168.0.6:8080`.. what else could be still causing the prob?.. I tried locally. – Sami Aug 13 '12 at 20:54
  • If you can't access http://192.168.0.6:8080 and you have the SelectChannelConnector@0.0.0.0:8080 output, then you don't have a 192.168.0.6 as a network interface on that machine. Try running a test from java to see if it can find that network interface. http://docs.oracle.com/javase/tutorial/networking/nifs/listing.html – Joakim Erdfelt Aug 13 '12 at 22:57
  • I ran this code and that's part of what I got: `Display name: Intel(R) Centrino(R) Advanced-N 6205 Name: net5 InetAddress: /192.168.0.6 InetAddress: /fe80:0:0:0:c739:e32:3450:159f%19 ` – Sami Aug 14 '12 at 21:25
  • 1
    How do you configure this when Jetty is launched automatically from eclipse? (run as web application) – Nilzor Feb 20 '13 at 13:45
  • Note: In Android Studio with Google App Engine you have to edit the file .iml. Change the line `` to `` – fklappan Feb 08 '16 at 19:27
1

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);
Oliver
  • 1,218
  • 1
  • 17
  • 21
0

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

  • This is not a solution to the problem posted in the question, as the asker clearly states that Jetty is accessible from localhost via IPv4. – lxg Sep 09 '14 at 20:08
  • No he doesn't. He states he can reach it from localhost:8080 on machine A, which can be (and usually are) aliased to both IPv4 (127.0.0.1) and IPv6 (::1) subsets simultaneously. The fact that many clients and jetty will cascade from one to the other without telling you which is in use/which has failed, plays heavily into the issue. Most likely, his 127.0.0.1:8080 on A is locked but his ::1:8080 is not and jetty is using the latter. – Matt Hilliard Sep 09 '14 at 22:22
  • Ok, that does sound plausible. – lxg Sep 09 '14 at 22:31