Ensure right java version is detected

If JAVA_HOME points to a different java than is on the path, then the java version will be incorrectly detected.

I haven't of course tested this fix, but given that exactly the same command is run a few lines up, I think it's probably fine.