来自Mac OS上的maven“入门”示例(jersey / grizzly“Got it!”)(OS X yosemite 10.10.2 java 1.7.025)我生成了一个可自行执行的jar,它在Mac OS上运行得很好(无论是过度卷曲还是浏览器)但是如果我在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)。
是否有人通过在不同的操作系统上运行相同的代码已经观察到此行为?任何提示在哪里搜索?
提前感谢您的帮助
亲切的问候
安托
答案 0 :(得分:0)
不是真正的答案,更多的是Windows 7 6.1 64位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>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!