0

jax-rs HelloWorld の例を組み合わせて、実行可能な jarを構築しています

私の期待は、1 つの JAR ファイル内にすべての依存関係を含むこの hello world を作成することです。

heroku パッケージを抽出した後、これを pom.xml に追加します (2 番目の説明で説明したように + メイン クラスを編集して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. 私は : に自分の jar を持っています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

私が間違っていることは何ですか?

4

1 に答える 1

0

prj を github などにアップロードできますか? 間違ったスコープにいくつかの依存関係があるようです。

于 2013-09-14T17:38:06.040 に答える