What Jersey version do I need to download for JDK 1.9?

前端 未结 3 553
日久生厌
日久生厌 2021-02-09 04:22

I am using jdk 1.9. I am trying to bring up a simple ReST service. Created the project using the maven archetype: jersey-quickstart-webapp. Then I went ahead and mo

相关标签:
3条回答
  • 2021-02-09 04:38

    The problem that current Jersey has a shaded asm 5 dependency, which doesn't work with Java 9 bytecode. Looks like Jersey 1.x is not adopted to Java 9 and it's unclear if this support is coming at all. As a temporary solution, I made a branch where I deleted shaded asm, migrated packages in code to use a regular asm dependency and put asm 6.0 in maven dependencies.

    You can build only jersey-server and jersey-servlet modules from this branch because only these two depend on asm and use these two custom artifacts in your project.

    My projects work fine with such a replacement, but I can't guarantee that it's 100% working solution, I wasn't able to build the whole distribution without fails and can't invest time for a full adoption and check right now. On the same time, the main Jersey parts built without issues.

    So, your final pom would look like:

    <!--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>
    
    0 讨论(0)
  • 2021-02-09 04:45

    I was getting this error and in my case it had nothing to do with the version of Jersey. It was due to some elastic-search jars namely (elastic-search, elastic-search-core and log4j.2.1.1) that were multi-release jars. Multi-release jars have a folder named version that has some artifacts inside the META-INF. I deleted that folder and it resolved the issue.

    java #jersey #rest #elasticsearch

    0 讨论(0)
  • 2021-02-09 05:01

    There are quite a few artifacts that you might need to update. To start with you shall check your module's mvn dependency:tree to look out for any source of asm that brings in version < 6.0.x since that is not compatible with Java9. From the current pom.xml and as inferred from your execution logs, you can update

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

    to

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

    Importantly, use Java 9 compatible maven plugins such as -

    <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>
    

    On a side note, you might end up still facing some other challenges(I can see conflicting jaxb dependencies, even asm might be transitive from jersey) to resolve which you shall run

    mvn dependency:analyze
    

    and make sure that conflicting dependencies are excluded in such cases to make use of their updated version.

    0 讨论(0)
提交回复
热议问题