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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23541532/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 23:44:35  来源:igfitidea点击:

org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15

javaeclipsetomcatjava-8classformatexception

提问by HymanTurky

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

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

Tomcat starts successfully but in log catalina.outI get:

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)

What could be the problem?

可能是什么问题呢?

采纳答案by rmuller

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

“官方答案”是 Tomcat 7 在 Java 8 上运行,请参阅 http://tomcat.apache.org/whichversion.html(“Java版本 6 及更高版本”)。

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):

但是,如果启用了注释扫描(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)

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

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

(UPDATE 2014-10-17) If your areusing annotation scanning andyour 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):

(更新 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

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

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

回答by Saulo Silva

Update to Tomcat 7.0.58 (or newer).

更新到 Tomcat 7.0.58(或更新版本)。

See: https://bz.apache.org/bugzilla/show_bug.cgi?id=57173#c16

参见:https: //bz.apache.org/bugzilla/show_bug.cgi?id=57173#c16

The performance improvement that triggered this regression has been reverted from from trunk, 8.0.x (for 8.0.16 onwards) and 7.0.x (for 7.0.58 onwards) and will not be reapplied.

触发此回归的性能改进已从主干、8.0.x(8.0.16 及更高版本)和 7.0.x(7.0.58 及更高版本)恢复,并且不会重新应用。

回答by Neelam Chahal

I faced this issue with tomcat 7 + jdk 1.8

我在使用 tomcat 7 + jdk 1.8 时遇到了这个问题

with java 1.7 and lower versions it's working fine.

使用 java 1.7 和更低版本它工作正常。

window -> preferences -> java -> installed jre

窗口 -> 首选项 -> java -> 已安装的 jre

in my case I changed jre1.8 to JDK 1.7

就我而言,我将 jre1.8 更改为 JDK 1.7

and accordingly modify project facet , select same java version as it's there in selected Installed JRE.

并相应地修改项目方面,选择与所选已安装 JRE 中相同的 Java 版本。

回答by vallismortis

This was a Tomcat bugthat resurfaced again with the Java 9 bytecode. The exact versions which fix this (for both Java 8/9 bytecode) are:

这是一个Tomcat 错误,随着 Java 9 字节码再次出现。解决此问题的确切版本(对于 Java 8/9 字节码)是:

  • trunk for 9.0.0.M18 onwards
  • 8.5.x for 8.5.12 onwards
  • 8.0.x for 8.0.42 onwards
  • 7.0.x for 7.0.76 onwards
  • 9.0.0.M18 以后的后备箱
  • 8.5.12 以后的 8.5.x
  • 8.0.42 以后的 8.0.x
  • 7.0.x 为 7.0.76 或更高版本

回答by C Karthickeyan

This issue is happening because you have installed jre1.8.0_101-1.8.0_101-fcs.i58.rpm as well jdk-1.7.0_80-fcs.x86_64.rpm. so just uninstall your jre rpm & restart your application. It should work out.

发生此问题是因为您已安装 jre1.8.0_101-1.8.0_101-fcs.i58.rpm 以及 jdk-1.7.0_80-fcs.x86_64.rpm。所以只需卸载您的 jre rpm 并重新启动您的应用程序。它应该工作。

回答by Cody

To me, upgrading bcel to 6.0 fixed the problem.

对我来说,将 bcel 升级到 6.0 解决了这个问题。

回答by y?lmaz

I got similar error (org.aspectj.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15) while using aspectj 1.8.13. Solution was to align all compilation into jdk 8 and being careful not to put aspectj library's (1.6.13 for instance) other versions to buildpath/classpath.

我在使用 aspectj 1.8.13 时遇到了类似的错误(org.aspectj.apache.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15)。解决方案是将所有编译对齐到 jdk 8 并注意不要将 aspectj 库(例如 1.6.13)的其他版本放到 buildpath/classpath 中。

回答by Andreas Panagiotidis

For me it worked, by removing the jars in question from the war. With Maven, I just had to exclude for example

对我来说,通过从War中移除有问题的罐子,它起作用了。使用 Maven,我只需要排除例如

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>${resteasy.version}</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.istack</groupId>
                <artifactId>istack-commons-runtime</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jvnet.staxex</groupId>
                <artifactId>stax-ex</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.glassfish.jaxb</groupId>
                <artifactId>txw2</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.xml.fastinfoset</groupId>
                <artifactId>FastInfoset</artifactId>
            </exclusion>
        </exclusions>
    </dependency>