I am trying to run a Jersey server on my local OS X machine.
So far, I have executed these three commands as per the Jersey website instruction:
mvn archetype:generate -DarchetypeArtifactId=jersey-quickstart-grizzly2 \
-DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
-DgroupId=com.example -DartifactId=simple-service -Dpackage=com.example \
-DarchetypeVersion=2.14
mvn clean test
mvn exec:java
It appears to be working fine, in that the last command prints this:
Dec 17, 2014 12:05:15 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [localhost:8080]
Dec 17, 2014 12:05:15 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Jersey app started with WADL available at http://localhost:8080/myapp/application.wadl
Hit enter to stop it...
However, when trying to call http://localhost:8080
in the browser, I get an address unreachable error. I have also tested it with telnet:
telnet localhost 8080
Which returns a connection refused error. Clearly, the Jersey servlet "thinks" it's listening locally on port 8080, but it's definitely not. I have tried reaching it using 127.0.0.1
instead of localhost, and I have tried running Jersey on a different port. Nothing seems to be able to fix it.
I'm running Jersey 2.1.4 with Maven 3.2.3 on OS X 10.10 and using Java 1.8.0.
EDIT: There is no firewall blocking incoming connections. I have turned it off to eliminate that possibility.
Ok guys, I have found the solution.
The default base URI is http://localhost:8080/myapp
. You can see it in Main.java
, in line 16:
public static final String BASE_URI = "http://localhost:8080/myapp/";
I changed localhost
to 0.0.0.0
, and it worked!
public static final String BASE_URI = "http://0.0.0.0:8080/myapp/";
Thank you very much for your help, and I am sorry that I ended up answering my own question. I hope it helps some people in the future.