当前位置: 首页 > 面试题库 >

org.apache.tomcat.util.bcel.classfile.ClassFormatException:常量池中的无效字节标记:15

程景胜
2023-03-14
问题内容

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

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

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及更高版本”)。

但是,如果启用了注释扫描(web.xml中的metadata-complete =“ true”),则由于BCEL(无法处理新的Java 8字节代码)而会出现一些问题。你将获得类似的异常(至少对于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支持的更新的编译器)开始,一切正常。

(UPDATE二○一四年十月一十七日)如果你正在使用注解扫描和自己的代码是不是Java 8为主,另一种解决方案是添加以下行/etc/tomcat7/catalina.properties(“蚂蚁launcher.jar”之后添加文本,以便物业部分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进行了测试。



 类似资料: