Error: Invalid or corrupt jarfile

- 2 mins read

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:

Git Config

- 1 min read

My .gitconfig contains

[user]
        email = dan@bodar.com
        name = Daniel Bodart
[color]
        ui = true
[alias]
        ci = commit
        co = checkout
        st = status -sb
        nuke = !git checkout -f && git clean -xf -d
[push]
        default = current
[filter "lfs"]
        clean = git-lfs clean -- %f
        smudge = git-lfs smudge -- %f
        process = git-lfs filter-process
        required = true

Wat? Scala

- 1 min read

As I got quoted recently in “Scala — 1★ Would Not Program Again” I though I finally should write up a little Wat moment we had recently:

So does anyone know “wat” the following Scala code returns? (Value and Type)

List(1,2,3).toSet()

A Set<Int> containing 1,2,3?

Nope how about I give you a clue, there are 2 bugs in this one line:

  1. A type inferencing bug where it chooses Set<Any>
  2. A bug where the brackets are used for both calling the Set.apply method and constructing Unit, notice there no space between the “toSet” and “()”

Yup you guessed it, it returns:

An alternative approach to just doing CSV export (which is fast and more cross platform/app) is to use web queries (.iqy files that point to fairly HTML) or data queries (.dqy extension but point to the DB)

Pro

  • Supports refreshing data / live data model
  • Web based integration
  • Very easy to do
  • Works with all versions since excel 97
  • They support linking back into you app via urls (IQY only) so we had cells that said edit that took you back to the web app.
  • Auto sorting, pivoting is a doddle

Cons

Mercurial settings

- 1 min read
[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

If you use C3PO you can make it do it when it checks the connection out.

As properties:

c3p0.preferredTestQuery=alter session set current_schema=animals
c3p0.testConnectionOnCheckout=true

As Java code:

ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setPreferredTestQuery("alter session set current_schema=animals");
dataSource.setTestConnectionOnCheckout(true);

Downside is this will happen every time the connection is taken out of the pool

If you are using a JDBC connection yourself you could just do:

Class.forName("oracle.jdbc.driver.OracleDriver");
Connection connection = getConnection("jdbc:oracle:thin:@//server:1521/instance", "username", "password");
connection.createStatement().execute("alter session set current_schema=animals"));

I also posted it to StackOverflow