2013-08-29 28 views
0

我結合jax-rs HelloWorld examplebuilding executable jar如何使這個作品嵌入式

我的期望是到裏面一個JAR文件的所有依賴創造這個世界你好。

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 

我在做什麼錯了?

回答

0

你可以上傳prj到github什麼的?看起來你在錯誤的範圍內有一些依賴關係。

+0

嗨。鏈接是我Q的第一句話。這裏是:https://github.com/jesperfj/jax-rs-heroku。在Q中只發布了對POM的控制。在這種方法失敗之後,我切換到了Jetty。但是我也很樂意做嵌入式Grizzly。 – flyer

相關問題