Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to instruct Maven to use JDK other than the one specified at JAVA_HOME?

Tags:

java

maven

Currently my JAVA_HOME is set to a JDK that is 1.4.2.

To run Maven 3, I would need 1.5 and above.

Is there any way to instruct my Maven installation to use another JDK that is installed other than changing the JAVA_HOME environment variable?

like image 531
Oh Chin Boon Avatar asked Sep 03 '11 13:09

Oh Chin Boon


People also ask

Does Maven require JAVA_HOME?

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.

How do I change my Java home path?

To set JAVA_HOME, do the following: Right click My Computer and select Properties. On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located, for example, C:\Program Files\Java\jdk1. 6.0_02.


1 Answers

On Windows:

STEP 1:

Find apache-maven-3.2.1\bin\mvn.bat, then find and replace JAVA_HOME to JAVA_HOME_MVN. Note: Before this, make a backup of mvn.bat

STEP 2:

Create a new environment variable called JAVA_HOME_MVN and point it to the bin of whichever jdk you want to use.

like image 107
YashxRaj Avatar answered Sep 22 '22 05:09

YashxRaj