
Apache Maven Cookbook
By :

It is possible to have more than one version of JDK installed on your system. By following some simple steps, you can specify and/or change the JDK to be used by Maven.
You will recall that, in the earlier section, we used Java SE 7. Let us now change to Java SE 8. To change the JDK version to Java SE 8 on Microsoft Windows, perform the following steps:
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_20
export JAVA_HOME=<java-8-home-folder>
mvn –version
C:\projects\apache-maven-cookbook>mvn -version
The output for the preceding command is shown as:
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T22:59:23+05:30)
Maven home: C:\software\apache-maven-3.2.5
Java version: 1.8.0_20, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_20\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"
Maven always uses the JDK specified by JAVA_HOME
, no matter how many JDK installations are available on the system. This allows the user the flexibility to change JDKs as required or based on the project.
Hence, it is important to ensure JAVA_HOME
is defined. In the absence of this variable, Maven attempts to detect the presence of Java from PATH
. This is typically JRE and not JDK.