2

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.

4

2 に答える 2

1

わかりました、私は解決策を見つけました。

デフォルトのベース URI はhttp://localhost:8080/myapp. Main.javaの 16 行目で確認できます。

public static final String BASE_URI = "http://localhost:8080/myapp/";

に変更localhostしましたが0.0.0.0、うまくいきました!

public static final String BASE_URI = "http://0.0.0.0:8080/myapp/";

ご協力ありがとうございました。自分の質問に答えてしまい申し訳ありません。将来、一部の人々に役立つことを願っています。

于 2014-12-18T11:45:17.007 に答える
0

グラスフィッシュ スタックを使用する必要がない場合: 私はアーキタイプを好む

com.sun.jersey.archetypes:jersey-quickstart-webapp

桟橋付き:

pom のプラグイン セクションで、glassfish プラグインを次のように置き換えます。

<plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.2.2.v20140723</version> </plugin>

これで残りのサービスを実行できますmvn jetty:run

幸運を

于 2014-12-17T16:26:32.853 に答える