Add support for building java binding out-of-tree

This is similar to #99.

Cheers!