Nov 1, 2018

How to configure Java version for Maven

During start-up, Maven reads two files /etc/mavenrc and ~/.mavenrc. All you had to do is to create one of these files and assign path to Java directory to JAVA_HOME environment variable there.

So my /etc/mavenrc looks like this:

JAVA_HOME=/usr/java/latest

You can run mvn --version to verify it:

$ /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven3.1.1/bin/mvn --version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 15:22:22+0000)
Maven home: /var/lib/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven3.1.1
Java version: 1.8.0_66, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_66/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.4.76-65.111.amzn1.x86_64", arch: "amd64", family: "unix"