【问题标题】:Tomcat 7 Annotation scanner and JDK 8 with -parameters compiler flag exceptionsTomcat 7 注释扫描器和带有 -parameters 编译器标志异常的 JDK 8
【发布时间】:2014-10-06 10:23:46
【问题描述】:

我正在使用带有 -parameters 标志的 JDK 8 编译我的类文件,该标志保留参数名称并通过反射使它们可用。 Tomcat 7 似乎与我的类文件有问题。

Aug 13, 2014 8:31:32 AM org.apache.catalina.startup.ContextConfig processAnnotationsFile
SEVERE: Unable to process file [/home/rex/apache-tomcat-7.0.54/webapps/ROOT/WEB-INF/classes/mod/test/TestData.class] for annotations
java.io.EOFException
        at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340)
        at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:797)
        at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:171)
        at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:57)
        at org.apache.tomcat.util.bcel.classfile.Method.<init>(Method.java:71)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:267)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:127)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2058)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2033)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2026)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsFile(ContextConfig.java:2026)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1291)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)

我正在使用 Tomcat 7.0.54 和 JDK 8u5 x64 任何帮助将不胜感激:)

【问题讨论】:

    标签: java tomcat annotations java-8


    【解决方案1】:

    已确认在 Tomcat 7.0.56 中修复

    查看 Tomcat 7.0.56 http://tomcat.apache.org/tomcat-7.0-doc/changelog.html 的更新日志

    也在本地对此进行了测试,它解决了我的问题

    【讨论】:

    • 我认为它已在 7.0.58 中修复:57173: Revert the fix for 56953 that broke annotation scanning in some cases. (markt)
    【解决方案2】:

    这是正确的,您必须禁用注释处理,有关更多信息,请参阅此问题org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15

    【讨论】:

    • 该标志非常适合自动填充 servlet 请求方法的参数,类似于 Springs @PathVariable。这在以前的实现中是不可能的,这是 JAVA 8 中一个值得欢迎的变化
    【解决方案3】:

    我遇到了同样的问题,我没有升级tomcat版本就解决了,如下:

    1. 更改 jaassist 版本(我使用的是 3.20.0-GA 版本,我将其更改为 3.18.1-GA)

    2. 为 maven 编译器插件添加一些 args

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>${plugin.compiler.version}</version>
          <configuration>
              <source>${project.build.javaVersion}</source>
              <target>${project.build.javaVersion}</target>
              <forceJavacCompilerUse>true</forceJavacCompilerUse>
              <fork>true</fork>
              <compilerArgument>-proc:none</compilerArgument>             
          </configuration>
      </plugin>
      
    3. 将标签 metadata-complete="true" 添加到 web.xml

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多