One would expect this behavior but alas this is not the case.
Unfortunately JAVA_HOME is overwritten by the mvn script to use that defined in /etc/java/maven.conf
so its not possible to change the version used by maven by setting the JAVA_HOME
environment variable.
. /etc/java/maven.conf
On re-reading the /usr/bin/mvn
bash script I see there is an environment variable MAVEN_SKIP_RC
which, if set, will cause mvn
to ignore maven.conf
and thus not override JAVA_HOME
.
This is not actually ideal (I think) as maven is then run with (perhaps) and incomparable java version.
My problem is that the java files compiled by maven have Java 17 features that fail when compiled with Java 11. I’m OK with maven running under Java 11 but need the files compiled using the Java to specified by JAVA_HOME
.
In /usr/bin/mvn
, maven is run with the java specified in JAVACMD
.
if [ -z "$JAVA_HOME" ] ; then
JAVACMD=`which java`
else
JAVACMD="$JAVA_HOME/bin/java"
fi
It looks to me that a better solution is to set JAVACMD
to specific Java version of the installed maven libraries (e.g. 11) and leave aloneJAVA_HOME
so that the user java files are compiled as expected.