如何使这个工作嵌入

时间:2013-08-29 13:48:42

标签: maven jersey grizzly embedded-server

我正在组合jax-rs HelloWorld examplebuilding executable jar

我的期望是在一个JAR文件中创建所有依赖项的hello world。

在提取heroku包之后,我将其添加到pom.xml中(如第二次讨论中所描述的+编辑主类到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

我做错了什么?

1 个答案:

答案 0 :(得分:0)

你能把prj上传到github吗?看起来你在错误的范围内有一些依赖。

相关问题