build script to use JAVA_HOME if defined

Fixes Issue #985