The shell script outputs $JAVA_VERSION. In my case, in an ill-fated attempt to get maven to use JDK 1.4, this was set to 1.4 but JAVA_HOME was already set (in .profile or wherever) to that of the current JDK (1.5). So it is inconsistent and led me on a wild goose chase to track down a problem. If Maven is going to output the java version, do it from java code using the right system property. Only use JAVA_VERSION to help select a JAVA_HOME, if JAVA_HOME isn't set.
Perhaps there is some standard approach to this sort of thing but I am unsure.