Tomcat unexpectedly throws ClassFormatError at startup

I have a problem with my project, and after some testing, I don’t think this is due to the source. Even if I return to the previous working revision, I still get an error message when I try to deploy Tomcat.

The org.springframework.beans.factory.BeanDefinitionStoreException error org.springframework.beans.factory.BeanDefinitionStoreException caused by java.lang.ClassFormatError with the message File with a truncated class .

I started narrowing down the problem by removing Eclipse from the equation, but even when using the maven command line and deploying directly to my tomcat instance, I still get the same problem. There were people on Google who made the mistake of offering to clear the tomcat and temp directory, which I did with no luck.

I know that this is not a lot of information, but provided that the problem is not in my code, what changes in my system can cause a sudden manifestation of this problem?


Stack trace

 Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [beans.xml]; nested exception is java.lang.ClassFormatError: Truncated class file at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:239) ... 54 more Caused by: java.lang.ClassFormatError: Truncated class file at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1847) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:890) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1354) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233) at org.apache.xbean.spring.context.v2c.XBeanQNameHelper.loadClass(XBeanQNameHelper.java:102) at org.apache.xbean.spring.context.v2c.XBeanQNameHelper.getBeanInfo(XBeanQNameHelper.java:72) at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.getPropertyDescriptor(XBeanNamespaceHandler.java:581) at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.addAttributeProperties(XBeanNamespaceHandler.java:333) at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parseBeanFromExtensionElement(XBeanNamespaceHandler.java:225) at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parseBeanFromExtensionElement(XBeanNamespaceHandler.java:276) at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parse(XBeanNamespaceHandler.java:156) at org.apache.xbean.spring.context.v2.XBeanNamespaceHandler.parse(XBeanNamespaceHandler.java:49) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1419) at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140) at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) ... 59 more 
+4
source share
9 answers

It seems that one of the class files is damaged, but the problem is to find which one.

One way to debug is to use the eclipse break on exception function. Start tomcat so that it waits for the debugger to be connected before starting , then break the java.lang.ClassFormatError to be thrown, and examine the local variables and stack in eclipse to see which class is not loading.

+5
source

If you run JSP, just go to your TOMCAT_HOME / work / Catalina / localhost / directory, find your webapp name, cd, and go down from the directory tree from there until you find the JSP class files .. sudo rm -f * and try again .

No need to reinstall everything or rebuild anything, nothing you did was damaged. Sometimes the compiler gets confused.

+4
source

If that were so. The same exception will be thrown for all web applications and they cannot be damaged. I also tried to remove and re-deploy wars, check the disk for bad sectors, etc. Finally, the removal and reinstallation of tomcat7 is fixed.

 apt-get purge tomcat7 apt-get install tomcat7 

The root cause remains a mystery.

0
source

I tried a lot to get out of this problem, but finally I found it, this is not a problem with a damaged .class file. these are corrupted .class files stored on your local server (Tomcat7, etc.). so

  • delete your server.
  • clean the project (in the menu bar: Prject β†’ clean)
  • add it again to your eclipse.
  • clean up the project and install using maven.
  • run the project.

be happy coding.

0
source

I deleted the destination folder and cleared the compilation, and now everything is fine.

0
source

The problem is that your class / jar file containing the class file is corrupted. Find the package for which class you are getting this error. If its file is cleaned and rebuilt, it should solve the problem. If the problem arises due to some external package, overload is down and it should solve your problem.

If you are using maven, delete your local m2 repository and rebuild.

0
source

Such errors can occur if the class you are working on is corrupted. If the problem is with the class you are working on, just do a clean build and the problem will be solved.

If the error occurs due to a third-party JAR / API, reloading the same file in most cases will solve the problem.

If you are using the build tool / framework, delete the existing repository and run the tool.

0
source

Yes, the last class of the file I'm working on can cause problems when starting the application. I did not make this class from the main class and now works fine.

0
source

This question is quite old at the moment, but I remember the situation quite clearly, despite the fact that it was 4 years ago.

The underlying cause of this problem in this case was that my disk was damaged due to a firmware problem. I had similar things that happened to me in other situations due to a memory failure or disk failure for other reasons.

The reason I post this after so long is because I see a lot of answers that have localized solutions to this problem. YMMV and corruption can occur without a complete disk or memory failure, but consider this PSA answer.

If you encounter this problem or similar problems, take the time to check the integrity of your disk and RAM. These types of problems can only be the tip of the iceberg.

0
source

Source: https://habr.com/ru/post/1397256/


All Articles