我正在结合jax-rs HelloWorld 示例并构建可执行 jar
我的期望是在一个 JAR 文件中创建这个包含所有依赖项的 hello world。
提取 heroku 包后,我将其添加到 pom.xml 中(如第二次讨论中所述 + 将主类编辑为 just Main
):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
之后我建立:> mvn package
. 我的罐子在 : target/jax-rs-heroku-1.0-SNAPSHOT-jar-with-dependencies.jar
。我将 PORT 环境变量设置为 8080。我使用以下命令运行 jar:
>java -jar jax-rs-heroku-1.0-SNAPSHOT-jar-with-dependencies.jar
Starting grizzly...
2013-08-29 15:33:27 com.sun.grizzly.Controller logVersion
INFO: Starting Grizzly Framework 1.9.18-i - Thu Aug 29 15:33:27 CEST 2013
Jersey started with WADL available at http://localhost:8080/application.wadl.
到目前为止一切看起来都很完美!现在,如果我访问该页面:
http://localhost:8080/application.wadl
真正的问题从这里开始。浏览器给了我一个Server error
. 访问该页面后,控制台日志中出现异常:
INFO: Scanning for root resource and provider classes in the packages:
resources
2013-08-29 15:37:14 com.sun.jersey.api.core.ScanningResourceConfig logClasses
INFO: Root resource classes found:
class resources.HelloResource
2013-08-29 15:37:14 com.sun.jersey.api.core.ScanningResourceConfig init
INFO: No provider classes found.
2013-08-29 15:37:14 com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
INFO: Initiating Jersey application, version 'Jersey: 1.9.1 09/14/2011 02:05 PM'
2013-08-29 15:37:14 com.sun.jersey.server.wadl.generators.WadlGeneratorJAXBGrammarGenerator attachTypes
INFO: Couldn't find JAX-B element for class java.lang.String
2013-08-29 15:37:14 com.sun.jersey.spi.container.ContainerResponse write
SEVERE: A message body writer for Java class java.io.ByteArrayInputStream, and Java type class java.io.ByteArrayInputStream, and MIME media
type application/xml was not found
2013-08-29 15:37:14 com.sun.jersey.spi.container.ContainerResponse write
SEVERE: The registered message body writers compatible with the MIME media type are:
*/* ->
com.sun.jersey.server.impl.template.ViewableMessageBodyWriter
2013-08-29 15:37:14 com.sun.jersey.spi.container.ContainerResponse logException
SEVERE: Mapped exception to response: 500 (Internal Server Error)
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class java.io.ByteArrayInputStream,
and Java type class java.io.ByteArrayInputStream, and MIME media type application/xml was not found
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:285)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at com.sun.grizzly.http.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:195)
at com.sun.grizzly.http.servlet.FilterChainImpl.invokeFilterChain(FilterChainImpl.java:139)
at com.sun.grizzly.http.servlet.ServletAdapter.doService(ServletAdapter.java:376)
at com.sun.grizzly.http.servlet.ServletAdapter.service(ServletAdapter.java:324)
at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class java.io.ByteArrayInputStream, and Java type class java.
io.ByteArrayInputStream, and MIME media type application/xml was not found
... 27 more
我做错了什么?