本文介绍了org.apache.tomcat.util.bcel.classfile.ClassFormatException:常量池中的字节标记无效:15的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 web 应用程序从 Tomcat 7 移植到另一台使用 Tomcat 7 但使用 Java 8 的服务器.

I'm porting a webapp from Tomcat 7 to another server with Tomcat 7 but with Java 8.

Tomcat 成功启动,但在日志 catalina.out 中我得到:

Tomcat starts successfully but in log catalina.out I get:

org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15
    at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131)
    at org.apache.tomcat.util.bcel.classfile.ConstantPool.<init>(ConstantPool.java:60)
    at org.apache.tomcat.util.bcel.classfile.ClassParser.readConstantPool(ClassParser.java:209)
    at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:119)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2049)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1931)
    at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1899)
    at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1885)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1281)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:855)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:346)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5172)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:618)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1100)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1618)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

可能是什么问题?

推荐答案

官方答案"是 Tomcat 7 在 Java 8 上运行,见http://tomcat.apache.org/whichversion.html(Java 6 及更高版本").

The "offical answer" is that Tomcat 7 runs on Java 8, seehttp://tomcat.apache.org/whichversion.html ("Java version 6 and later").

但是,如果启用了注释扫描(web.xml 中的 metadata-complete="true"),则会由于 BCEL(无法处理新的 Java 8 字节代码)而出现一些问题.你会得到这样的异常(至少在 Tomcat 7.0.28 中):

However, if annotation scanning is enabled (metadata-complete="true" in web.xml) there are some issues due to BCEL (not able to process the new Java 8 byte codes). You will get exceptions like (at least with Tomcat 7.0.28):

SEVERE: Unable to process Jar entry [jdk/nashorn/internal/objects/NativeString.class] from Jar [jar:file:/usr/lib/jvm/jdk1.8.0_5/jre/lib/ext/nashorn.jar!/] for annotations
org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15
    at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131)

如果使用注释扫描,一切正常,从 7.0.53 版开始(更新的编译器具有更好的 Java 8 支持).

If not using annotation scanning, everything works fine, starting release 7.0.53 (updated compiler with better Java 8 support).

(更新 2014-10-17)如果您正在使用注释扫描并且您自己的代码不是基于 Java 8 的,另一种解决方案是在 /etc/tomcat7/catalina.properties 中添加以下行(在ant-launcher.jar"之后添加文本,因此属性tomcat.util.scan.DefaultJarScanner.jarsToSkip的一部分):

(UPDATE 2014-10-17)If your are using annotation scanning and your own code is not Java 8 based, another solution is to add the following line in /etc/tomcat7/catalina.properties (text added after "ant-launcher.jar" so part of property tomcat.util.scan.DefaultJarScanner.jarsToSkip):

junit.jar,junit-*.jar,ant-launcher.jar,
jfxrt.jar,nashorn.jar

在 Debian 7.6 上使用 Tomcat 7.0.28 和 Oracle JDK 8_25 进行测试.

Tested with Tomcat 7.0.28 and Oracle JDK 8_25 on Debian 7.6.

这篇关于org.apache.tomcat.util.bcel.classfile.ClassFormatException:常量池中的字节标记无效:15的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 00:03