How to set specific java version to Maven

andPat picture andPat · Oct 29, 2013 · Viewed 291.3k times · Source

On my machine I have two java versions installed: (1.6 and 1.7 installed manually by me). I need both of them for different projects. But for Maven I need 1.7, now my Maven uses 1,6 java version, how can I set Maven to use 1.7?

Answer

DanielBarbarian picture DanielBarbarian · Oct 29, 2013

Maven uses the JAVA_HOME parameter to find which Java version it is supposed to run. I see from your comment that you can't change that in the configuration.

  • You can set the JAVA_HOME parameter just before you start maven (and change it back afterwards if need be).
  • You could also go into your mvn(non-windows)/mvn.bat/mvn.cmd(windows) and set your java version explicitly there.