简体   繁体   English

GAE ClassFormatError:不兼容的魔法值4022320623 EFBFBDEF

[英]GAE ClassFormatError: Incompatible magic value 4022320623 EFBFBDEF

I have a simple webapp in an mavenized Eclipse project. 我在一个mavenized Eclipse项目中有一个简单的webapp。 My pom.xml contains some lines that add Google's appengine-maven-plugin to the build plugins. 我的pom.xml包含一些将Google的appengine-maven-plugin添加到构建插件的行。

When I run mvn appengine:devserver I eventually get an error telling me that my class could not be loaded: 当我运行mvn appengine:devserver我最终得到一个错误,告诉我我的类无法加载:

[INFO] WARNING: Error starting handlers [INFO] java.lang.ClassFormatError: Incompatible magic value 4022320623 in class file com/teamlazerbeez/http/di/StartupListener [INFO]警告:启动处理程序时出错[INFO] java.lang.ClassFormatError:类文件中的不兼容的魔术值4022320623 com / teamlazerbeez / http / di / StartupListener

That number is EFBFBDEF in hexadecimal notation, something that is clearly not CAFEBABE , the byte sequence Java class files should start with. 这个数字是EFBFBDEF十六进制的,这东西显然不是CAFEBABE ,该字节序列Java类文件应该开始。 I only found this and this on the subject matter, which leads me to believe that the encoding went wrong during either writing or reading the class file. 我只在主题上找到了这个这个 ,这让我相信在编写或读取类文件时编码出错了。

Is this the problem? 这是问题吗? How do I force maven to read/write classes with eg UTF-8 encoding? 如何强制maven使用例如UTF-8编码读/写类? And what is a good encoding? 什么好的编码?
My java files are all encoded the same way: Eclipse says ISO-8859-1, Notepad++ says ANSI. 我的java文件都以相同的方式编码:Eclipse表示ISO-8859-1,Notepad ++表示ANSI。

PS: I'm on a windows machine. PS:我在一台Windows机器上。

As Joakim Erdfeld 's answer suggests, one of the plugins is fiddling with the build. 正如Joakim Erdfeld回答所暗示的那样,其中一个插件正在摆弄这个版本。 The culprit is the maven-war-plugin v2.3, but only in the following situation: 罪魁祸首是maven-war-plugin v2.3,但仅限于以下情况:

Having the GAE nature enabled on the mavenized Ecipse project (where the appengine-maven-plugin v1.7.5 is listed in the pom.xml ) will break running mvn appengine:devserver iff the following conditions apply: 在mavenized Ecipse项目上启用GAE特性(其中appengine-maven-plugin v1.7.5在pom.xml列出)将破坏运行mvn appengine:devserver iff以下条件适用:

  • 'default output folder' (in the Eclipse project's 'Build Path' settings) is set to src/main/webapp/WEB-INF/classes/ (required for the GAE Eclipse plugin to work) 'default output folder'(在Eclipse项目的'Build Path'设置中)设置为src/main/webapp/WEB-INF/classes/ (GAE Eclipse插件工作所需)
  • The GAE plugin decided to put GAE-jars in src/main/webapp/WEB-INF/lib/ , even though these jars are already in the classpath. GAE插件决定将GAE-jars放在src/main/webapp/WEB-INF/lib/ ,即使这些jar已经在类路径中。

In conclusion, the maven-war-plugin improperly copies .class and .jar files from your WEB-INF/ to your resulting .war file. 总之,maven-war-plugin不正确地将.class和.jar文件从WEB-INF/复制到生成的.war文件中。 Somewhere in the process, it mis-encodes these files. 在这个过程的某个地方,它错误地编码了这些文件。

Check your src/main/webapp/WEB-INF folder, it should not contain a classes folder. 检查你的src/main/webapp/WEB-INF文件夹,它不应该包含classes文件夹。

If it does, it means you probably misconfigured your eclipse project. 如果是这样,这意味着您可能错误配置了您的eclipse项目。

One case we encountered is that the developer imports a maven project and runs the project "as a web application". 我们遇到的一个案例是开发人员导入maven项目并“作为Web应用程序”运行项目。 The first time he does this, Eclipse asks him where the webapp folder is. 他第一次这样做时,Eclipse会问他webapp文件夹的位置。 If you answer src/main/webapp then Eclipse will put its classes there, and it will get messed up by maven after. 如果你回答src/main/webapp那么Eclipse会把它的类放在那里,之后它会被maven搞砸了。

To solve this, delete the project from Eclipse and remove the src/main/webapp/WEB-INF/classes folder, then re-import the project . 要解决此问题,请从Eclipse中删除项目并删除src/main/webapp/WEB-INF/classes folder, then re-import the project

And when Eclipse asks where the webapp folder is, it is in target/yourproject-yourversion . 当Eclipse询问webapp文件夹的位置时,它位于target/yourproject-yourversion

Something in your maven build is messing with the class files after the compile and before the package phases. maven构建中的某些东西在compilepackage阶段之前弄乱了类文件。

Start by commenting out all of your <plugins> and then adding them back 1 at a time till the build breaks again. 首先注释掉所有<plugins> ,然后一次添加1个,直到构建再次中断。

Be sure you run > mvn help:effective-pom to check on what your pom looks like when it has been fully resolved to parent poms and whatnot. 确保你运行> mvn help:effective-pom来检查你的pom完全解析为父母pom之后的样子。

(Experimental) You can possibly even get the build itself to tell you if the classes are bad by simply using the project-info-reports command line for the dependencies report. (实验)您甚至可以通过简单地使用项目信息报告命令行来获取依赖项报告,从而获得构建本身以告诉您类是否错误。

> mvn clean org.apache.maven.plugins:maven-project-info-reports-plugin:2.6:dependencies

I found this question which also mentioned the invalid magic number EFBFBDEF. 我发现这个问题还提到了无效的幻数EFBFBDEF。 It also seems to suggest that you set the maven encodings properly. 它似乎也建议您正确设置maven编码。 Use the following property: 使用以下属性:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

But I think that this only helps if you get an encoding warning during the maven build process. 但我认为这只有在maven构建过程中收到编码警告时才有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM