Make Java detection more robust