2

I have a simple webapp in an mavenized Eclipse project. My pom.xml contains some lines that add Google's appengine-maven-plugin to the build plugins.

When I run mvn appengine:devserver I eventually get an error telling me that my class could not be loaded:

[INFO] WARNING: Error starting handlers [INFO] java.lang.ClassFormatError: Incompatible magic value 4022320623 in class file 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. 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 e.g. UTF-8 encoding? And what is a good encoding?
My java files are all encoded the same way: Eclipse says ISO-8859-1, Notepad++ says ANSI.

PS: I'm on a windows machine.

Community
  • 1
  • 1
derabbink
  • 2,419
  • 1
  • 22
  • 47

4 Answers4

4

As Joakim Erdfeld's answer suggests, one of the plugins is fiddling with the build. The culprit is the maven-war-plugin v2.3, but only in the following situation:

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:

  • '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)
  • The GAE plugin decided to put GAE-jars in src/main/webapp/WEB-INF/lib/, even though these jars are already in the classpath.

In conclusion, the maven-war-plugin improperly copies .class and .jar files from your WEB-INF/ to your resulting .war file. Somewhere in the process, it mis-encodes these files.

Community
  • 1
  • 1
derabbink
  • 2,419
  • 1
  • 22
  • 47
3

Check your src/main/webapp/WEB-INF folder, it should not contain a classes folder.

If it does, it means you probably misconfigured your eclipse project.

One case we encountered is that the developer imports a maven project and runs the project "as a web application". The first time he does this, Eclipse asks him where the webapp folder is. If you answer src/main/webapp then Eclipse will put its classes there, and it will get messed up by maven after.

To solve this, delete the project from Eclipse and remove the 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.

David
  • 5,481
  • 2
  • 20
  • 33
1

Something in your maven build is messing with the class files after the compile and before the package phases.

Start by commenting out all of your <plugins> and then adding them back 1 at a time till the build breaks again.

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.

(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
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • You were right, the problem seems to be with the maven-war-plugin. Right now I suspect that having a mavenized GAE Eclipse project that is a GAE project as well, will not work. Changing the maven-war-plugin configuration makes the .class files work, but then it will destroy my GAE system library dependency jars. I'll investigate further. – derabbink Mar 06 '13 at 21:30
1

I found this question which also mentioned the invalid magic number EFBFBDEF. It also seems to suggest that you set the maven encodings properly. 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.

Community
  • 1
  • 1