2017-10-15 18 views
4

私はjdk 1.9を使用しています。私は簡単なReSTサービスを提供しようとしています。 Maven Archetype:jersey-quickstart-webappを使用してプロジェクトを作成しました。それから、pom.xmlとweb.xmlを修正しました。JDK 1.9のダウンロードに必要なJerseyのバージョンは何ですか?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 

    <modelVersion>4.0.0</modelVersion> 

    <groupId>restWebService</groupId> 
    <artifactId>restWebService</artifactId> 
    <packaging>war</packaging> 
    <version>1.0-SNAPSHOT</version> 
    <name>restWebService</name> 

    <build> 
     <finalName>restWebService</finalName> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.7.0</version> 
       <inherited>true</inherited> 
       <configuration> 
        <source>9</source> 
        <target>9</target> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

    <dependencyManagement> 
     <dependencies> 
      <dependency> 
       <groupId>org.glassfish.jersey</groupId> 
       <artifactId>jersey-bom</artifactId> 
       <version>${jersey.version}</version> 
       <type>pom</type> 
       <scope>import</scope> 
      </dependency> 
     </dependencies> 
    </dependencyManagement> 

    <dependencies> 
     <!-- https://mvnrepository.com/artifact/org.springframework/spring-core --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>5.0.0.RELEASE</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-client --> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-client</artifactId> 
      <version>1.19.4</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-bundle --> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-bundle</artifactId> 
      <version>1.19.4</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-server --> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-server</artifactId> 
      <version>1.19.4</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core --> 
     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-core</artifactId> 
      <version>1.19.4</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/asm/asm --> 
     <dependency> 
      <groupId>org.ow2.asm</groupId> 
      <artifactId>asm</artifactId> 
      <version>6.0_BETA</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/org.json/json --> 
     <dependency> 
      <groupId>org.json</groupId> 
      <artifactId>json</artifactId> 
      <version>20170516</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-impl --> 
     <dependency> 
      <groupId>com.sun.xml.bind</groupId> 
      <artifactId>jaxb-impl</artifactId> 
      <version>2.3.0</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/javax.xml/jaxb-api --> 
     <dependency> 
      <groupId>javax.xml</groupId> 
      <artifactId>jaxb-api</artifactId> 
      <version>2.1</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/javax.activation/activation --> 
     <dependency> 
      <groupId>javax.activation</groupId> 
      <artifactId>activation</artifactId> 
      <version>1.1.1</version> 
     </dependency> 

     <dependency> 
      <groupId>com.sun.jersey</groupId> 
      <artifactId>jersey-json</artifactId> 
      <version>1.19.4</version> 
     </dependency> 

     <!-- https://mvnrepository.com/artifact/com.sun.xml.bind/jaxb-core --> 
     <dependency> 
      <groupId>com.sun.xml.bind</groupId> 
      <artifactId>jaxb-core</artifactId> 
      <version>2.3.0</version> 
     </dependency> 

    </dependencies> 
    <properties> 
     <jersey.version>2.16</jersey.version> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 
</project> 

とweb.xmlは次のようになります:下図のように私のMavenの設定がある私は、このURLをヒットしようとすると

<?xml version="1.0" encoding="UTF-8"?> 
<!-- This web.xml file is not required when using Servlet 3.0 container, 
    see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
    <servlet> 
     <servlet-name>Jersey REST Service</servlet-name> 
     <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
     <init-param> 
      <param-name>com.sun.jersey.config.property.packages</param-name> 
      <param-value>restWebService</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Jersey REST Service</servlet-name> 
     <url-pattern>/webapi/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

http://localhost:8080/webapi/myresource - 私は次のエラーを参照してください。

HTTP Status 500 – Internal Server Error 

Type Exception Report 

Message Servlet.init() for servlet [Jersey REST Service] threw exception 

Description The server encountered an unexpected condition that prevented it from fulfilling the request. 

Exception 

javax.servlet.ServletException: Servlet.init() for servlet [Jersey REST Service] threw exception 
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475) 
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) 
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651) 
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) 
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:500) 
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) 
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:754) 
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1376) 
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) 
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
    java.base/java.lang.Thread.run(Thread.java:844) 
Root Cause 

java.lang.IllegalArgumentException 
    jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:170) 
    jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:153) 
    jersey.repackaged.org.objectweb.asm.ClassReader.<init>(ClassReader.java:424) 
    com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:138) 
    com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner$1.f(FileSchemeScanner.java:86) 
    com.sun.jersey.core.util.Closing.f(Closing.java:71) 

私は1.9から1.8

<configuration> 
    <source>1.8</source> 
    <target>1.8</target> 
</configuration> 
にビルド構成を変更

サービスは何の問題もなく起き、ブラウザには期待された結果が表示されます。私はのIntelliJ、プロジェクトSDK使用しています

から9は、プロジェクト言語レベル - 9

は、私はそれが1.9で動作させるために、どのようなjarファイルをインポートする必要がありますか?または、動作させるためにmavenの設定を変更する必要がありますか?

EDIT:依存関係ツリー

[INFO] Scanning for projects... 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building restWebService 1.0-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[WARNING] The artifact javax.xml:jaxb-api:jar:2.1 has been relocated to javax.xml.bind:jaxb-api:jar:2.1 
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ restWebService --- 
[WARNING] The artifact javax.xml:jaxb-api:jar:2.1 has been relocated to javax.xml.bind:jaxb-api:jar:2.1 
[INFO] restWebService:restWebService:war:1.0-SNAPSHOT 
[INFO] +- org.springframework:spring-core:jar:5.0.0.RELEASE:compile 
[INFO] | \- org.springframework:spring-jcl:jar:5.0.0.RELEASE:compile 
[INFO] +- com.sun.jersey:jersey-client:jar:1.19.4:compile 
[INFO] +- com.sun.jersey:jersey-bundle:jar:1.19.4:compile 
[INFO] | \- javax.ws.rs:jsr311-api:jar:1.1.1:compile 
[INFO] +- com.sun.jersey:jersey-server:jar:1.19.4:compile 
[INFO] +- com.sun.jersey:jersey-core:jar:1.19.4:compile 
[INFO] +- org.ow2.asm:asm:jar:6.0_BETA:compile 
[INFO] +- org.json:json:jar:20170516:compile 
[INFO] +- com.sun.xml.bind:jaxb-impl:jar:2.3.0:compile 
[INFO] +- javax.xml.bind:jaxb-api:jar:2.1:compile 
[INFO] | \- javax.xml.stream:stax-api:jar:1.0-2:compile 
[INFO] +- javax.activation:activation:jar:1.1.1:compile 
[INFO] +- com.sun.jersey:jersey-json:jar:1.19.4:compile 
[INFO] | +- org.codehaus.jettison:jettison:jar:1.1:compile 
[INFO] | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.2:compile 
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.2:compile 
[INFO] | +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.2:compile 
[INFO] | \- org.codehaus.jackson:jackson-xc:jar:1.9.2:compile 
[INFO] \- com.sun.xml.bind:jaxb-core:jar:2.3.0:compile 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1.910 s 
[INFO] Finished at: 2017-10-14T22:05:15-04:00 
[INFO] Final Memory: 13M/44M 
[INFO] ------------------------------------------------------------------------ 

答えて

2

あなたが更新する必要があるかもしれないかなりの数のアーティファクトがあります。まず、あなたのモジュールのmvn dependency:treeを調べて、asmのソースがあり、それがバージョン< 6.0.xになるのはJava9と互換性がないためです。現在pom.xmlからして、実行ログから推測されるように、あなたのようなJava 9 compatible maven pluginsを使用し、

重要な
<dependency> 
    <groupId>org.ow2.asm</groupId> 
    <artifactId>asm</artifactId> 
    <version>6.0</version> 
</dependency> 

<!-- https://mvnrepository.com/artifact/asm/asm --> 
<dependency> 
    <groupId>asm</groupId> 
    <artifactId>asm</artifactId> 
    <version>3.3.1</version> 
</dependency> 

を更新することができます -

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <version>3.7.0</version> 
    <inherited>true</inherited> 
    <configuration> 
     <source>9</source> 
     <target>9</target> 
    </configuration> 
</plugin> 

副メモでは、あなたはまだいくつかの他の課題に直面して終わるかもしれないあなたが

mvn dependency:analyze 

を実行して、競合の依存関係を作るために、このような例では除外されていることを確認しなければならないどの解決するために(私はjaxb依存関係を矛盾見ることができます、でもasmjerseyからの推移であるかもしれません)更新されたバージョンの使用。

+0

ありがとう:

だから、最終的なポンポンは次のようになります。しかし、私はあなたの変更をpom.xmlに組み込んだ後も同じエラーが発生します。 –

+0

@RahulDevMishra答えに記載されているように他のソースから 'asm'を呼び出さない依存関係ツリーを見つけようとしましたか? – nullpointer

+0

今すぐやりましょう –

1

Java 9バイトコードでは動作しない現在のJerseyには影付きのasm 5依存関係があるという問題があります。 Jersey 1.xがJava 9に採用されていないように見えますが、このサポートがまったく行われているかどうかは不明です。一時的な解決策として、私はbranchを作成しました。シェーディングされたasmを削除し、正規のasm依存関係を使用し、maven依存関係にasm 6.0を入れるコードでパッケージを移行しました。

これらの2つだけがasmに依存し、これらの2つのカスタム成果物をプロジェクトで使用するため、このブランチからjersey-serverおよびjersey-servletモジュールのみをビルドできます。

私のプロジェクトはそのような置き換えでうまくいっていますが、100%実用的なソリューションであるとは保証できません。私は失敗せずに配布全体を構築することができず、たった今。同時に、主要ジャージーの部品は問題なく建設されました。提案のための

<!--regular jersey dependencies with the last 1.19.4 version--> 
<dependency> 
    <groupId>com.sun.jersey</groupId> 
    <artifactId>jersey-server</artifactId> 
    <version>${custom-jersey-with-asm6.version}</version> 
</dependency> 

<dependency> 
    <groupId>com.sun.jersey</groupId> 
    <artifactId>jersey-servlet</artifactId> 
    <version>${custom-jersey-with-asm6.version}</version> 
</dependency> 

<dependency> 
    <groupId>org.ow2.asm</groupId> 
    <artifactId>asm</artifactId> 
    <version>6.0</version> 
</dependency> 
関連する問題