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

我把一个webapp从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支持)。

(更新2014-10-17)
如果您使用注释扫描,并且您自己的代码不是基于Java 8的,另一个解决方案是在/etc/tomcat7/catalina.properties中添加以下行(在“ant-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进行测试。

转载注明原文:eclipse – org.apache.tomcat.util.bcel.classfile.ClassFormatException:常量池中的无效字节标记:15 - 代码日志