-->

Maven is suddenly throwing error, Truncated class

2019-06-14 11:23发布

问题:

Yesterday Maven is working fine,,today it shows that problem,I tried backup also it does not work ,and for your information tomcat is working fine its a maven problem ,and I uninstall maven and install it again and all things before posting this question

{Stack trace: 
    -----------------------------------------------------------------------
    Exception in thread "main" java.lang.ClassFormatError: Truncated class file
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:30)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:588)
        at sun.reflect.annotation.AnnotationParser.annotationForMap(AnnotationParser.java:239)
        at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:229)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
        at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
        at java.lang.reflect.Field.declaredAnnotations(Field.java:1016)
        at java.lang.reflect.Field.getAnnotation(Field.java:1000)
        at com.google.inject.spi.InjectionPoint.getAtInject(InjectionPoint.java:468)
        at com.google.inject.spi.InjectionPoint.getInjectionPoints(InjectionPoint.java:653)
        at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:358)
        at com.google.inject.spi.InjectionPoint.forInstanceMethodsAndFields(InjectionPoint.java:377)
        at com.google.inject.internal.BindingBuilder.toProvider(BindingBuilder.java:106)
        at com.google.inject.internal.BindingBuilder.toProvider(BindingBuilder.java:43)
        at org.sonatype.guice.plexus.binders.PlexusTypeBinder.hear(PlexusTypeBinder.java:85)
        at org.sonatype.guice.plexus.binders.PlexusXmlBeanModule.configure(PlexusXmlBeanModule.java:91)
        at org.sonatype.guice.plexus.binders.PlexusBindingModule.configure(PlexusBindingModule.java:62)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
        at com.google.inject.spi.Elements.getElements(Elements.java:103)
        at com.google.inject.spi.Elements.getElements(Elements.java:80)
        at org.sonatype.guice.bean.binders.MergedModule.configure(MergedModule.java:54)
        at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
        at com.google.inject.spi.Elements.getElements(Elements.java:103)
        at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
        at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
        at com.google.inject.Guice.createInjector(Guice.java:94)
        at com.google.inject.Guice.createInjector(Guice.java:71)
        at com.google.inject.Guice.createInjector(Guice.java:61)
        at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:470)
        at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:196)
        at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:160)
        at org.apache.maven.cli.MavenCli.container(MavenCli.java:375)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:191)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)}

回答1:

Clean your maven repository:

(By default in your user folder)

~/.m2/repository

Then perform a clean install so it download the dependencies again and recompile your entire project:

mvn clean install


回答2:

ClassFormatError: Truncated class file 

means that one of the class file is corrupted. Try to run clean goal to do the bad classes cleanup before you run the install target. Or simply combine both the targets and do mvn clean install for your project.



回答3:

I can see from your stac-trace that you are using reflection. Is the class working when you use it normally? Is it possible that when you use reflection, the class is unreachable or mis-used?



回答4:

After all the research and changing things, i found the solution, I updated Maven dependency,it doesn't work,

I uninstall tomcat and Java and then reinstall it.

And the error is that Java Jdk is corrupted due to some reason i Dont Know it why.....

and thanks all for your suggestions