Changing the JDK used by Maven

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.

How to do it...

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:

  1. From the command prompt, run the following command:
    set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_20
    
  2. For Linux or Mac, the command will be:
    export JAVA_HOME=<java-8-home-folder>
    
  3. Now, run the following command to check the version of Maven installed:
    mvn –version
    
  4. To check the version of Maven installed on Microsoft Windows, run the following command from the ...

Get Apache Maven Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.