Java - 什么导致 ClassFormatError?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10021752/
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
Java - What Causes ClassFormatError?
提问by WildBamaBoy
When running program from Eclipse it works fine.
从 Eclipse 运行程序时它工作正常。
When running it outside of Eclipse I get this:
在 Eclipse 之外运行它时,我得到了这个:
java.lang.ClassFormatError: Duplicate method name&signature in class file [Class Name]
The class in question implements from an interface, and the program has several other classes that extend from the class mentioned in the error.
有问题的类是从接口实现的,程序还有几个其他类,这些类是从错误中提到的类扩展而来的。
What causes this and how is it fixed?
这是什么原因造成的,如何解决?
回答by Sam Rueby
Thrown when the Java Virtual Machine attempts to read a class file and determines that the file is malformed or otherwise cannot be interpreted as a class file.
当 Java 虚拟机尝试读取类文件并确定该文件格式错误或无法解释为类文件时抛出。
http://docs.oracle.com/javase/7/docs/api/java/lang/ClassFormatError.html
http://docs.oracle.com/javase/7/docs/api/java/lang/ClassFormatError.html
The Javadocs are your friend.
Javadoc 是您的朋友。
回答by Vladimir Filipchenko
I had the same issue. As for me, root cause was that aspectj plugin compiles sources two times. Aspect class leaves in 'service' module and compiles with aspectJ plugin. And then it comes already compile into top-level 'web' module as dependency and complies once again (because 'service' module was as 'weaveDependency' in 'web' module's aspectJ plugin config). Solution: I've replaced next configuration in 'web' module
我遇到过同样的问题。至于我,根本原因是 aspectj 插件编译源代码两次。Aspect 类留在“服务”模块中并使用 aspectJ 插件进行编译。然后它已经作为依赖项编译到顶级“web”模块中并再次遵守(因为“service”模块在“web”模块的aspectJ插件配置中是“weaveDependency”)。解决方案:我已经替换了“web”模块中的下一个配置
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<weaveDependencies>
<weaveDependency>
<groupId>com.taxi.core</groupId>
<artifactId>service</artifactId>
</weaveDependency>
</weaveDependencies>
</configuration>
with
和
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<aspectLibraries>
<aspectLibrary>
<groupId>com.taxi.core</groupId>
<artifactId>service</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
回答by AVA
Googled and Found that Disabling "Deploy on save" may help to overcome the problem. Try on test platform and go for production!
谷歌搜索并发现禁用“保存时部署”可能有助于解决该问题。在测试平台上试用并投入生产!