Category Archives: memory

Error: Invalid or corrupt jarfile

I was creating a Jar via the Java API’s and I couldn’t get it to run my main class:

 $ java -jar foo.jar
Error: Invalid or corrupt jarfile foo.jar

Running it via the class path worked fine:

 $ java -cp foo.jar Bar
Hello world!

So now I knew it was something to do with the manifest file but it wasn’t being caused by

  • The 65535 file limit (See Zip64 and Java 7 ).
  • The 72 bytes limit per line
  • Missing newline at the end of the Main-Class (Displays “no main manifest attribute, in foo.jar”
  • A blank line before Main-Class (Displays “Error: An unexpected error occurred while trying to open file foo.jar”

So after scratching my head for a while I tried comparing a working jar with the failing jar:

$ unzip -lv foo.jar 
Archive:  foo.jar
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
      75  Defl:N       75   0% 2014-02-17 16:01 b1eac370  META-INF/MANIFEST.MF
     825  Defl:N      464  44% 2014-02-17 16:01 942f187c  Working.class
$ unzip -lv foo.jar 
Archive:  foo.jar
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
      75  Defl:N       75   0% 2014-02-17 16:01 b1eac370  /META-INF/MANIFEST.MF
     825  Defl:N      464  44% 2014-02-17 16:01 942f187c  Failing.class

So don’t prefix the META-INF folder with a slash! Also note it is case sensitive!

Git Config

My .gitconfig contains

[user]
        email = dan@bodar.com
        name = Daniel Worthington-Bodart
[color]
        ui = true
[alias]
        ci = commit
        co = checkout
        st = status -sb
        nuke = !git checkout -f && git clean -f -d
[push]
        default = simple

Mercurial settings

[extensions]
hgext.bookmarks =
rebase =
hgext.purge =
color = 

[ui]
username = Daniel Worthington-Bodart <***@*****.com>

[merge-tools]
meld.executable = meld
meld.args = $local $base $other -o $output

[auth]
google.prefix = code.google.com
google.username = **********
google.password = **********
google.schemes = http https

[alias]
pull = pull --rebase
nuke = !$HG revert --all --no-backup ; $HG purge