Thursday, February 10, 2011

Corrupted jar file complains invalid CEN header (bad signature)

When do maven build, we see below error info:
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
error: error reading /home/root/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar; invalid CEN header (bad signature)

error: error reading /home/root/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16.jar; invalid CEN header (bad signature)

[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 13 seconds
[INFO] Finished at: Thu Feb 10 09:54:17 PST 2011
[INFO] Final Memory: 52M/138M
[INFO] ------------------------------------------------------------------------


The root cause is jar file (in this case log4j-1.2.16.jar) corrupted. Jar file is de facto a Zip file which should be in binary format. The binaries can get corrupted if checked in from a windows system as text files, due to line ending conversion, and to keyword substitution. Therefore when we check in the jar file to CVS, need mark them as binary.

On Windows systems check-out of a non-binary file can lead to conversion of one-character line-endings to two-character - which corrupts a true binary like a jar. You might not notice this when checking out the same file on a unix/linux system as there is no special treatment for "text" files when checking out there.

We can use WinZip, 7-Zip to verify if the jar file is corrupted or not.

1 comment:

  1. One possible cause is user check in jar files to CVS using text instead of binary which will corrupt the zip(jar) file.

    ReplyDelete