mvn jetty:run failing Caused by: java.lang.RuntimeException: Error scanning entry META-INF/versions/9/javax/xml/bind/ModuleUtil.class

huangapple go评论72阅读模式
英文:

mvn jetty:run failing Caused by: java.lang.RuntimeException: Error scanning entry META-INF/versions/9/javax/xml/bind/ModuleUtil.class

问题

我正在尝试在项目上执行 mvn jetty:run,但是这个过程一直失败,我无法在本地运行项目。从错误堆栈跟踪中,我认为一个相关的焦点是 Caused by: java.lang.RuntimeException: Error scanning entry META-INF/versions/9/javax/xml/bind/ModuleUtil.class from jar file:///C:/Users/Tabish/.m2/repository/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar。我尝试过更改 jaxb 的版本,但无济于事。

以下是错误追踪:

[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext@4998e74b{/myntra-v4-proxy,[file:///C:/Users/Tabish/Documents/Increff/Code/proxies/myntra-v4-proxy/target/webapp-tmp/, jar:file:///C:/Users/Tabish/.m2/repository/io/springfox/springfox-swagger-ui/2.4.0/springfox-swagger-ui-2.4.0.jar!/META-INF/resources],STARTING}{file:///C:/Users/Tabish/Documents/Increff/Code/proxies/myntra-v4-proxy/target/webapp-tmp/}
org.eclipse.jetty.util.MultiException: 多个异常
    at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations (AnnotationConfiguration.java:536)
    at org.eclipse.jetty.annotations.AnnotationConfiguration.configure (AnnotationConfiguration.java:447)
    at org.eclipse.jetty.webapp.WebAppContext.configure (WebAppContext.java:491)
    ...
Caused by: org.eclipse.jetty.util.MultiException: 多个异常
    ...
Caused by: java.lang.RuntimeException: 从 jar 文件:///C:/Users/Tabish/.m2/repository/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar 扫描条目 META-INF/versions/9/javax/xml/bind/ModuleUtil.class 时出错
    ...
Caused by: java.lang.IllegalArgumentException
    ...

我正在使用 jdk-11.0.2 运行。我的 pom.xml 文件包含以下依赖项和 Jetty 插件(其中之一可能导致问题):

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.el</artifactId>
            <version>3.0.0</version>
        </dependency>

        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.8</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
        </dependency>
...
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.7.v20160115</version>
            </plugin>
...

我该如何修复这个问题,以使项目能够在本地运行?

英文:

I am trying to perform an mvn jetty:run on my project, however, the process keeps failing and I can't get the project running locally. From the error stack trace, I think a relevant one to focus on is Caused by: java.lang.RuntimeException: Error scanning entry META-INF/versions/9/javax/xml/bind/ModuleUtil.class from jar file:///C:/Users/Tabish/.m2/repository/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar. I have tried changing the versions of jaxb but to no avail.

Here is the error trace

[WARNING] Failed startup of context o.e.j.m.p.JettyWebAppContext@4998e74b{/myntra-v4-proxy,[file:///C:/Users/Tabish/Documents/Increff/Code/proxies/myntra-v4-proxy/target/webapp-tmp/, jar:file:///C:/Users/Tabish/.m2/repository/io/springfox/springfox-swagger-ui/2.4.0/springfox-swagger-ui-2.4.0.jar!/META-INF/resources],STARTING}{file:///C:/Users/Tabish/Documents/Increff/Code/proxies/myntra-v4-proxy/target/webapp-tmp/}
org.eclipse.jetty.util.MultiException: Multiple exceptions
    at org.eclipse.jetty.annotations.AnnotationConfiguration.scanForAnnotations (AnnotationConfiguration.java:536)
    at org.eclipse.jetty.annotations.AnnotationConfiguration.configure (AnnotationConfiguration.java:447)
    at org.eclipse.jetty.webapp.WebAppContext.configure (WebAppContext.java:491)
    at org.eclipse.jetty.webapp.WebAppContext.startContext (WebAppContext.java:1336)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart (ContextHandler.java:772)
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart (ServletContextHandler.java:263)
    at org.eclipse.jetty.webapp.WebAppContext.doStart (WebAppContext.java:517)
    at org.eclipse.jetty.maven.plugin.JettyWebAppContext.doStart (JettyWebAppContext.java:398)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:61)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart (ContextHandlerCollection.java:161)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:132)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:114)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:61)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.start (ContainerLifeCycle.java:132)
    at org.eclipse.jetty.server.Server.start (Server.java:405)
    at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart (ContainerLifeCycle.java:106)
    at org.eclipse.jetty.server.handler.AbstractHandler.doStart (AbstractHandler.java:61)
    at org.eclipse.jetty.server.Server.doStart (Server.java:372)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start (AbstractLifeCycle.java:68)
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.startJetty (AbstractJettyMojo.java:460)
    at org.eclipse.jetty.maven.plugin.AbstractJettyMojo.execute (AbstractJettyMojo.java:328)
    at org.eclipse.jetty.maven.plugin.JettyRunMojo.execute (JettyRunMojo.java:170)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
Caused by: org.eclipse.jetty.util.MultiException: Multiple exceptions
    at org.eclipse.jetty.annotations.AnnotationParser.parseJar (AnnotationParser.java:923)
    at org.eclipse.jetty.annotations.AnnotationParser.parse (AnnotationParser.java:851)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call (AnnotationConfiguration.java:163)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run (AnnotationConfiguration.java:548)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run (QueuedThreadPool.java:572)
    at java.lang.Thread.run (Thread.java:834)
Caused by: java.lang.RuntimeException: Error scanning entry META-INF/versions/9/javax/xml/bind/ModuleUtil.class from jar file:///C:/Users/Tabish/.m2/repository/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar
    at org.eclipse.jetty.annotations.AnnotationParser.parseJar (AnnotationParser.java:937)
    at org.eclipse.jetty.annotations.AnnotationParser.parse (AnnotationParser.java:851)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call (AnnotationConfiguration.java:163)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run (AnnotationConfiguration.java:548)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run (QueuedThreadPool.java:572)
    at java.lang.Thread.run (Thread.java:834)
Caused by: java.lang.IllegalArgumentException
    at org.objectweb.asm.ClassReader.&lt;init&gt; (Unknown Source)
    at org.objectweb.asm.ClassReader.&lt;init&gt; (Unknown Source)
    at org.objectweb.asm.ClassReader.&lt;init&gt; (Unknown Source)
    at org.eclipse.jetty.annotations.AnnotationParser.scanClass (AnnotationParser.java:1003)
    at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry (AnnotationParser.java:984)
    at org.eclipse.jetty.annotations.AnnotationParser.parseJar (AnnotationParser.java:933)
    at org.eclipse.jetty.annotations.AnnotationParser.parse (AnnotationParser.java:851)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call (AnnotationConfiguration.java:163)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run (AnnotationConfiguration.java:548)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob (QueuedThreadPool.java:654)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run (QueuedThreadPool.java:572)
    at java.lang.Thread.run (Thread.java:834)
[INFO] Started ServerConnector@721bf7ad{HTTP/1.1,[http/1.1]}{0.0.0.0:9000}
[INFO] Started @31575ms
[INFO] Started Jetty Server

I am running with jdk-11.0.2. My pom.xml has the following dependencies and jetty plugin (one of which is causing the problem, I think)

        &lt;dependency&gt;
&lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
&lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
&lt;version&gt;2.3.1&lt;/version&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.glassfish&lt;/groupId&gt;
&lt;artifactId&gt;javax.el&lt;/artifactId&gt;
&lt;version&gt;3.0.0&lt;/version&gt;
&lt;/dependency&gt;
&lt;!-- Lombok --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
&lt;artifactId&gt;lombok&lt;/artifactId&gt;
&lt;version&gt;1.18.8&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;!-- https://mvnrepository.com/artifact/org.mockito/mockito-all --&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.mockito&lt;/groupId&gt;
&lt;artifactId&gt;mockito-all&lt;/artifactId&gt;
&lt;version&gt;${mockito.version}&lt;/version&gt;
&lt;/dependency&gt;
...
&lt;plugin&gt;
&lt;groupId&gt;org.eclipse.jetty&lt;/groupId&gt;
&lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;9.3.7.v20160115&lt;/version&gt;
&lt;/plugin&gt;
...

How can I fix this to allow my project to run on the local machine?

答案1

得分: 6

  1. 通过引用 pom of jaxb-api/2.3.0,目标 JDK 版本是 9。

  2. 通过查找 jetty-annotations/9.3.7.v20160115 的依赖,"org.ow2.asm/asm" 的依赖版本是 5.0.1。由于 JDK 9 在 2017 年 9 月发布,可以确定 asm 库不支持 Java 9,我们还可以参考 ClassReader 的源代码。

    public class ClassReader {
    ...
        /**
         * Constructs a new {@link ClassReader} object.
         * 
         * @param b
         *            the bytecode of the class to be read.
         * @param off
         *            the start offset of the class data.
         * @param len
         *            the length of the class data.
         */
        public ClassReader(final byte[] b, final int off, final int len) {
            this.b = b;
            // checks the class version
            if (readShort(off + 6) > Opcodes.V1_8) {
                throw new IllegalArgumentException();
            }
    ...
    }
    

    我们可以看到,如果类版本晚于 1.8,将会检查类版本。下面的程序展示了如何检查 jar 文件是否包含不支持 ClassReader 的类。

    import java.io.ByteArrayOutputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.jar.JarFile;
    
    import org.objectweb.asm.ClassReader;
    
    public class ClassReaderJarVersionCheck {
        public static void main(String[] args) throws FileNotFoundException, IOException {
            checkClassVersion();
        }
    
        private static void checkClassVersion() {
    
            String jarPath = "{path_to_jar}\\jaxb-api-2.3.0.jar";
            try (JarFile jarFile = new JarFile(jarPath)) {
                jarFile.stream().forEach(jarEntry -> {
                    if (jarEntry.isDirectory() || !jarEntry.getName().endsWith(".class")) {
                        return;
                    }
                    int version = -1;
                    try {
                        byte[] byteArray = toByteArray(jarFile.getInputStream(jarEntry));
                        version = readShort(byteArray, 6);
                        new ClassReader(byteArray);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    } catch (IllegalArgumentException e) {
                        System.out.println(jarEntry.getName() + " version: " + version);
                    }
                });
            } catch (IOException ioe) {
                throw new RuntimeException(ioe);
            }
        }
    
        private static short readShort(byte[] b, int index) {
            return (short) (((b[index] & 0xFF) << 8) | (b[index + 1] & 0xFF));
        }
    
        private static byte[] toByteArray(InputStream is) throws IOException {
            ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            int nRead;
            byte[] data = new byte[1024];
            while ((nRead = is.read(data, 0, data.length)) != -1) {
                buffer.write(data, 0, nRead);
            }
            buffer.flush();
            byte[] byteArray = buffer.toByteArray();
            return byteArray;
        }
    }
    

解决方案

升级 Jetty 以支持 JDK >= 11

通过参考 jetty 9.4.12 发布公告,将 jetty 的依赖更新到 版本 9.4.12 以支持 JDK 11 可以解决问题。

降级 jaxb-api 以支持 JDK 8

使用版本 2.2.11,因为 下一个版本 2.3.0 开始采用了 JDK 9

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.2.11</version>
    </dependency>
英文:
  1. By referring to pom of jaxb-api/2.3.0, the target jdk version is 9.
  2. By finding the dependency of jetty-annotations/9.3.7.v20160115, the dependency for
    "org.ow2.asm/asm" is 5.0.1
    As JDK 9 is release in September 2017, it is quite certain that the asm library will not support java 9, we can also refer to source code for ClassReader
public class ClassReader {
...
    /**
     * Constructs a new {@link ClassReader} object.
     * 
     * @param b
     *            the bytecode of the class to be read.
     * @param off
     *            the start offset of the class data.
     * @param len
     *            the length of the class data.
     */
    public ClassReader(final byte[] b, final int off, final int len) {
        this.b = b;
        // checks the class version
        if (readShort(off + 6) &gt; Opcodes.V1_8) {
            throw new IllegalArgumentException();
        }
...
}

We see that the class version is checked if the version is later than 1.8.
Following program show how to check if the jar contain class not supported for ClassReader.

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.JarFile;
import org.objectweb.asm.ClassReader;
public class ClassReaderJarVersionCheck {
public static void main(String[] args) throws FileNotFoundException, IOException {
checkClassVersion();
}
private static void checkClassVersion() {
String jarPath = &quot;{path_to_jar}\\jaxb-api-2.3.0.jar&quot;;
try (JarFile jarFile = new JarFile(jarPath)) {
jarFile.stream().forEach(jarEntry -&gt; {
if (jarEntry.isDirectory() || !jarEntry.getName().endsWith(&quot;.class&quot;)) {
return;
}
int version = -1;
try {
byte[] byteArray = toByteArray(jarFile.getInputStream(jarEntry));
version = readShort(byteArray, 6);
new ClassReader(byteArray);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
System.out.println(jarEntry.getName() + &quot; version: &quot; + version);
}
});
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
private static short readShort(byte[] b, int index) {
return (short) (((b[index] &amp; 0xFF) &lt;&lt; 8) | (b[index + 1] &amp; 0xFF));
}
private static byte[] toByteArray(InputStream is) throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[1024];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
byte[] byteArray = buffer.toByteArray();
return byteArray;
}
}

Solution

Upgrade Jetty for JDK>=11

By referring to jetty 9.4.12 release announcement, update the dependency of jetty to version 9.4.12 to support JDK 11 should solve the problem.

Downgrade jaxb-api for JDK 8

Use version 2.2.11 as the next version 2.3.0 start adopting JDK 9

        &lt;dependency&gt;
            &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
            &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
            &lt;version&gt;2.2.11&lt;/version&gt;
        &lt;/dependency&gt;

huangapple
  • 本文由 发表于 2020年9月16日 11:59:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63912913.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定