【问题标题】:Jersey/Grizzly "Getting Started" example on Linux/Windows or MacOS在 Linux/Windows 或 MacOS 上的 Jersey/Grizzly “入门”示例
【发布时间】:2015-03-29 08:07:32
【问题描述】:

从Mac OS(OS X yosemite 10.10.2 java 1.7.025)上的maven“入门”示例(jersey/grizzly“知道了!”)我生成了一个在Mac OS上运行完美的自我可执行jar (通过 curl 或使用浏览器)。但是,如果我在 Windows(Windows 7 企业 64 位 java 1.7.0.60)或 Linux(Suse x86_64 3.0.101-0 java 1.7.0)上运行相同的 jar,我会通过浏览器和 wget/curl 得到 404 答案来自 GET http://localhost:8080/my_app/myresource 但正确的 application.wasl 文件 (GET http://localhost:8080/my_app/application.wadl)。

是否有人已经通过在不同操作系统上运行相同的代码观察到了这种行为?任何提示在哪里搜索?

非常感谢您的帮助

亲切的问候

安东尼

【问题讨论】:

  • 应该是myapp 而不是my_app,如果您没有对原始原型进行任何更改

标签: jersey grizzly


【解决方案1】:

不是真正的答案,更多的是对 Windows 7 6.1 64bit Java 1.7.0_65 的参考(工作正常)

C:\temp>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.17

C:\temp>cd simple-service

C:\temp>simple-service> mvn package

C:\temp>simple-service>mvn exec:java [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building simple-service 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) @ simple-service >>> [INFO] [INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) @ simple-service <<< [INFO] [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ simple-service --- Mar 29, 2015 1:33:55 AM org.glassfish.grizzly.http.server.NetworkListener start INFO: Started listener bound to [localhost:8080] Mar 29, 2015 1:33:55 AM 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...

卷曲

C:\>curl http://localhost:8080/myapp/myresource Got it!

为了运行jar,添加了这两个插件

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.9</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.5</version>
    <configuration>
        <archive>
            <index>true</index>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                <mainClass>com.example.Main</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

重新打包运行

C:\temp\simple-service&gt;mvn clean package

C:\temp\simple-service>java -jar target/simple-service-1.0-SNAPSHOT.jar Mar 29, 2015 1:38:54 AM org.glassfish.grizzly.http.server.NetworkListener start INFO: Started listener bound to [localhost:8080] Mar 29, 2015 1:38:54 AM 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...

C:\>curl http://localhost:8080/myapp/myresource Got it!

【讨论】:

    猜你喜欢
    • 2012-08-06
    • 2014-07-17
    • 2018-04-24
    • 2011-08-28
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 2013-08-07
    相关资源
    最近更新 更多