You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Java 9后创建Tomcat及Jersey项目遇报错问题求助

Fixing ZipException/ExecutionException with Jersey 1.19 & Java 9

Alright, let's break down what's going wrong here and how to fix it.

Why This Happens

That ZipException leading to an ExecutionException is rooted in incompatibility between old ASM/Jersey versions and Java 9+'s bytecode & module system:

  • ASM 3.3.1 is a super old release (2012) — it has zero support for Java 9's new class file format and module structure. When it tries to parse Java 9-compiled classes, it chokes, throwing what looks like a zip error (since class files are technically zip-compatible).
  • Jersey 1.19 is part of the legacy 1.x branch, which was never updated to work with Java 9 or later. It relies on that outdated ASM version by default, and clashes with Java 9's stricter class loading rules.

Solutions

Option 1: Upgrade to a Java 9-compatible Jersey Version (Highly Recommended)

Ditch Jersey 1.x entirely and move to Jersey 2.x — versions 2.29.1 and above are built to support Java 9+. You won't even need to manually add ASM, since Jersey 2.x manages a compatible version under the hood.

Update your Maven dependencies to this:

<dependency>
    <groupId>org.glassfish.jersey.bundles</groupId>
    <artifactId>jersey-bundle</artifactId>
    <version>2.39.1</version>
</dependency>

Heads up: Jersey 2.x switched its groupId from com.sun.jersey to org.glassfish.jersey. Most of the JAX-RS core APIs (like javax.ws.rs) will still work, but you'll need to update any Jersey-specific imports from com.sun.jersey to org.glassfish.jersey.

Option 2: Force a Newer ASM Version (Temporary Workaround)

If you can't upgrade Jersey right now, you can override its outdated ASM dependency with a version that supports Java 9 (ASM 6.0+; 9.x is best):

<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm</artifactId>
    <version>9.5</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-bundle</artifactId>
    <version>1.19</version>
    <exclusions>
        <exclusion>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
        </exclusion>
    </exclusions>
</dependency>

Warning: This only fixes the bytecode parsing error. Jersey 1.x will still run into other issues on Java 9+ (like restricted reflection access), so this is just a short-term band-aid.

Option 3: Add Java 9 Module Permissions (For Option 2)

If you go with the workaround, you'll need to add these JVM arguments to your Tomcat startup to fix reflection access issues:

--add-modules java.se.ee
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.io=ALL-UNNAMED

These flags open up the restricted packages Jersey 1.x needs to access via reflection.

How to Verify

  1. Run mvn clean install to rebuild your project with the updated dependencies.
  2. Restart Tomcat and check if the ZipException error is gone.

内容的提问来源于stack exchange,提问作者Carlos López Marín

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:42:01