在我的项目中,我发现了这个异常 org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException。如何解决?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21852215/
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-09-10 22:01:47  来源:igfitidea点击:

In my project I found this exception org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException. How to resolve it?

eclipsetomcat7

提问by user3264898

org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException
    at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:372)
    at org.apache.jasper.compiler.JDTCompiler.findType(JDTCompiler.java:232)
    at org.apache.jasper.compiler.JDTCompiler.findType(JDTCompiler.java:188)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:113)
    at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(LookupEnvironment.java:1335)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromVariantTypeSignature(LookupEnvironment.java:1391)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeArgumentsFromSignature(LookupEnvironment.java:1172)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.getTypeFromTypeSignature(LookupEnvironment.java:1340)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethod(BinaryTypeBinding.java:550)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.createMethods(BinaryTypeBinding.java:630)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.cachePartsFrom(BinaryTypeBinding.java:365)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:688)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.createBinaryTypeFrom(LookupEnvironment.java:667)
    at org.eclipse.jdt.internal.compiler.Compiler.accept(Compiler.java:296)
    at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:118)
    at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:49)
    at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:122)
    at org.eclipse.jdt.internal.compiler.lookup.PackageBinding.getTypeOrPackage(PackageBinding.java:168)
    at org.eclipse.jdt.internal.compiler.lookup.Scope.getPackage(Scope.java:2379)
    at org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference.internalResolveLeafType(ParameterizedQualifiedTypeReference.java:138)
    at org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference.internalResolveType(ParameterizedQualifiedTypeReference.java:132)
    at org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference.resolveType(ParameterizedQualifiedTypeReference.java:351)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypeFor(SourceTypeBinding.java:1374)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.fields(SourceTypeBinding.java:699)
    at org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.faultInTypesForFieldsAndMethods(SourceTypeBinding.java:677)
    at org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope.faultInTypes(CompilationUnitScope.java:469)
    at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:756)
    at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:468)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:459)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

I am using Apache Tomcat/7.0.33, eclipse-jee-kepler-SR1-RC3-win32

我使用的是 Apache Tomcat/7.0.33,eclipse-jee-kepler-SR1-RC3-win32

回答by M Ali

Thanks much for the tips! Ran into same ClassFormatException error on Tomcat 6.0.20 and JDK1.8. Replaced the jasper-jdt.jar with ecj-4.2.2.jarand all the JSPs compiling/working again.

非常感谢您的提示!在 Tomcat 6.0.20 和 JDK1.8 上遇到相同的 ClassFormatException 错误。将 jasper-jdt.jar 替换为ecj-4.2.2.jar并且所有 JSP 再次编译/工作。

回答by hasnae

The problem is related to ecj version (ecj-3.7.2.jar), you have to use a more recent version of tomcat compatible with jdk8 (apache-tomcat-7.0.68 works fine for me )

问题与ecj版本(ecj-3.7.2.jar)有关,您必须使用与jdk8兼容的更新版本的tomcat(apache-tomcat-7.0.68对我来说很好用)

回答by Jar Yit

I hope the following steps will solve your problem.

我希望以下步骤可以解决您的问题。

1) Stop the tomcat.

1)停止tomcat。

2) Download ecj-4.2.2.jar in this link

2)在这个链接下载ecj-4.2.2.jar

3) Copy ecj-4.2.2.jar under tomcat's lib folder (example - C:\apache-tomcat-6.0.36\lib).

3) 将 ecj-4.2.2.jar 复制到 tomcat 的 lib 文件夹下(例如 - C:\apache-tomcat-6.0.36\lib)。

4) Rename ecj-3.7.2.jar to old_ecj-3.7.2.jar.

4) 将 ecj-3.7.2.jar 重命名为 old_ecj-3.7.2.jar。

5) Start the tomcat.

5)启动tomcat。

回答by Grim

If you use maven and jdk8 to start tomcat7, make sure that the version of the tomcat7-maven-pluginis at least 2.2

如果使用maven和jdk8启动tomcat7,请确保版本tomcat7-maven-plugin至少为2.2

回答by rajeesh

Remove existing localhost servers and add new server. This will solve your problem.

删除现有的本地主机服务器并添加新服务器。这将解决您的问题。

回答by dtelaroli

If you is using java 8 maybe you should update your eclipse version.

如果您使用的是 java 8,也许您应该更新您的 eclipse 版本。

Eclipse doc

日食文档

回答by Priyanshu

Going by the information in the stack trace, it seems that there is a compilation problem with the built in eclipse compiler which it uses rather than javac. All the Luna builds of Eclipse have support for jdk 8 but as you have mentioned that you are using Eclipse Kepler, you would have to download a feature patch from the eclipse community itself in order to support jdk 8.

根据堆栈跟踪中的信息,它使用的内置 eclipse 编译器似乎存在编译问题,而不是 javac。Eclipse 的所有 Luna 版本都支持 jdk 8,但正如您提到的,您使用的是 Eclipse Kepler,您必须从 Eclipse 社区本身下载功能补丁才能支持 jdk 8。

Meanwhile you can you use jdk 7 and recompile your project. See if the error goes away. Apart from that the code looks fine to me. I hope it helps. Happy to help.

同时,您可以使用 jdk 7 并重新编译您的项目。查看错误是否消失。除此之外,代码对我来说看起来不错。我希望它有帮助。乐于帮助。

回答by mvdb

I had the same problem using Tomcat 6 with Java 8. I solved it by configuring Tomcat to use Java 7 instead of 8: Add export JAVA_HOME=/usr/lib/jvm/java-7-oraclein your {tomcat-home}/bin/catalina.shor your custom startup script.

我在使用 Tomcat 6 和 Java 8 时遇到了同样的问题。我通过将 Tomcat 配置为使用 Java 7 而不是 8 解决了这个问题:JAVA_HOME=/usr/lib/jvm/java-7-oracle在您{tomcat-home}/bin/catalina.sh或您的自定义启动脚本中添加导出。

回答by ganesh raut

Check Your Tomcat Version.If your tomcat version 7.0.29 and below then Remove your Old Tomcat and Download latest one . And run the project https://tomcat.apache.org/download-90.cgi

检查您的 Tomcat 版本。如果您的 tomcat 版本为 7.0.29 及以下,则删除旧的 Tomcat 并下载最新版本。并运行项目 https://tomcat.apache.org/download-90.cgi

回答by shashigura

Note that 1. We cannot update the version of ECJ included with Tomcat 6, as Tomcat 6 must be able to run on Java 1.5, but current ECJ releases require minimum of Java 6.

请注意 1. 我们无法更新 Tomcat 6 中包含的 ECJ 版本,因为 Tomcat 6 必须能够在 Java 1.5 上运行,但当前的 ECJ 版本需要最低 Java 6。

  1. You may replace ecj-*.jar with a later version that you may download from http://www.eclipse.org/
  1. 您可以将 ecj-*.jar 替换为您可以从http://www.eclipse.org/下载的更高版本

See archives of Tomcat Users mailing list, and ask on the mailing list if you have questions. (Bugzilla is not a support forum).

查看 Tomcat 用户邮件列表的档案,如果您有问题,请在邮件列表中提问。(Bugzilla 不是支持论坛)。

  1. Tomcat can be configured to use Java javac compiler instead of Eclipse
  1. Tomcat 可以配置为使用 Java javac 编译器而不是 Eclipse