在jetty启动时抛出奇怪的java.lang.ArrayIndexOutOfBoundsException

时间:2014-10-21 21:07:18

标签: java jetty maven-jetty-plugin

每当我部署jetty应用程序时,我都遇到了这个问题。看起来有些jar或类已被破坏。

  • 同事编译完全相同的代码,没有遇到问题。即使部署到同一台计算机。 (我们使用gitmaven
  • 删除本地maven存储库~/.m2并重建无济于事。
  • 可以在本地运行相同的码头应用程序而不会出现任何问题。
  • 我最初的怀疑是有些jar被打破了。试过jar tvf $every_jar但没找到任何东西。

任何想法我该如何调试?看起来真的很神秘,我怀疑是有些文件被破坏了。

Stack trace:
2014-10-21 13:29:25.123:WARN:oejw.WebAppContext:Failed startup of context o.e.j.w.WebAppContext{/,file:/XYZ/},/XYZ/webapps/root
javax.servlet.ServletException: jersey-serlvet
        at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:553)
        at org.eclipse.jetty.servlet.ServletHolder.doStart(ServletHolder.java:344)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:791)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:265)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1242)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:717)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:494)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:39)
        at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:186)
        at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:494)
        at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:141)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:145)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:56)
        at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:615)
        at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:540)
        at org.eclipse.jetty.util.Scanner.scan(Scanner.java:403)
        at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:337)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:121)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:555)
        at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:230)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:81)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
        at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:96)
        at org.eclipse.jetty.server.Server.doStart(Server.java:282)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1274)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1197)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:473)
        at org.eclipse.jetty.start.Main.start(Main.java:615)
        at org.eclipse.jetty.start.Main.main(Main.java:96)

接着是

Caused by:
java.lang.ArrayIndexOutOfBoundsException: 6241
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at org.objectweb.asm.ClassReader.<init>(Unknown Source)
        at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:133)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner$1.f(FileSchemeScanner.java:86)
        at com.sun.jersey.core.util.Closing.f(Closing.java:71)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:83)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:80)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:80)
        at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scan(FileSchemeScanner.java:71)
        at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:223)
        at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139)
        at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80)
        at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
        at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
        at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
        at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:700)

4 个答案:

答案 0 :(得分:20)

对于你的2个错误..

javax.servlet.ServletException: jersey-serlvet

这意味着您的WEB-INF/web.xml

中有拼写错误

至于这一个..

java.lang.ArrayIndexOutOfBoundsException: 6241
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)

在使用旧版本的asm.jar和更新的编译Java字节码时,我见过类似的。

  • 对于Java 11字节码,请使用 asm 7.0 +
  • 对于Java 10字节码,请使用 asm 6.1 +
  • 对于Java 9字节码,请使用 asm 6.0 +
  • 对于Java 8字节码,请使用 asm 5.0.1 +
  • 对于Java 6或Java 7字节码,(如果必须,请使用 asm 3.1 ,但要知道 asm 5.x 也可以在这里工作)

确保您的asm.jar(或org.objectweb.asm.jar)是最新的。

在课程本身不好的情况下,有一个不太常见的问题。有时会看到在一个JDK(例如IBM)中编译的类,然后在另一个Java(如Sun / Oracle)上运行。

真实世界的例子是the icu4j-2.6.1.jar and its com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class jar entry

答案 1 :(得分:10)

使用较新版本的jetty-maven-plugin。

更多信息 - &gt; Bug 419801 - Upgrade to asm5 for jdk8

所以,请像这样编辑pom.xml

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.3.0.M2</version>
</plugin>

注意groupId是“ org.eclipse.jetty ”。

答案 2 :(得分:1)

我在维护遗留代码时遇到了类似的问题。

Servlet.init() for servlet JerseyServlet threw exception

type Exception report

message Servlet.init() for servlet JerseyServlet threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet JerseyServlet threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
    org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
    org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)
root cause

java.lang.ArrayIndexOutOfBoundsException
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.65 logs.

我通过减少web.xml中的包扫描范围来修复它。例如,删除param-value标签下面的package_with_too_many_classes修复了这个问题。

<servlet>
   <servlet-name>JerseyServlet</servlet-name>
   <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
   <init-param>
       <param-name>com.sun.jersey.config.property.packages</param-name>
       <param-value>package_with_too_many_classes;package_with_approciate_number_of_classes;org.codehaus.jackson.jaxrs</param-value>
   </init-param>
   <load-on-startup>2</load-on-startup>
 </servlet>

答案 3 :(得分:1)

就我而言,我使用的是ASM库版本,并且不支持java 8 lambda表达式,因此要么更改ASM库以支持java 8,要么更改代码。

在我的情况下,我使用java 8 lambda表达式进行迭代,并将其替换为for循环