January 2, 2017

Maven | How To Set Specific Java Version

This article is to learn how to set specific java version for maven in windows. As this might be required where java home set to one version and developer want to run maven command with specific another java version.4-l
To run maven with specific java, one need to update file mvn.bat file in bin folder. In mvn.bat file set java home explicitly as below.

@REM ==== START VALIDATION ====
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25\jre
if not "%JAVA_HOME%" == "" goto OkJHome

After saving mvn.bat, maven will run with respect to java home set in file.
One can verify this by firing command mvn command as below.
After setting up Java version in mvn.bat file, maven java version can be verified in command prompt.

C:\Users\e050125>java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

C:\Users\e050125>mvn -version
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:28+0530)
Maven home: C:\software\Maven\apache-maven-3.0.5
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_25\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
Share:

0 comments:

Post a Comment