Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven home (M2_HOME) not being picked up by IntelliJ IDEA

I am trying to do a simple maven build with IntelliJ IDEA 10.5.1 on OS X Lion and am getting the following error:

Error running my-app [package]: No valid Maven installation found. Either set the home directory in the configuration dialog or set the M2_HOME environment variable on your system.

I have set M2_HOME to the following, but I am still having issues. And yes, I did restart IntelliJ.

$ echo $M2_HOME /usr/share/maven 

I then manually entered the path to maven in IntelliJ's Maven Settings for the project. This is not something that I want to do for every project, so is there something I am missing with how to get IntelliJ know where my maven home is?

like image 937
Travis Nelson Avatar asked Aug 13 '11 22:08

Travis Nelson


People also ask

How do I change the Maven home directory in IntelliJ?

From the main menu select File | Settings/Preferences | Build, Execution, Deployment |Build Tools | Maven. On the Maven settings page, in the Maven home directory field, specify the location of the Maven custom version installation.

Is not a valid Maven home directory?

This error message means that the folder named "maven" that you've chosen does not contain maven installation. The default Maven Home Directory was the m2 folder. Normally, by default you'll see either the embeded maven or the value of M2_HOME environment variable.

How do I get Maven plugins for IntelliJ?

In the Project tool window, right-click your project and select Add Framework Support. In the dialog that opens, select Maven from the options on the left and click OK. IntelliJ IDEA adds a default POM to the project and generates the standard Maven layout in Project tool window.


2 Answers

Mac OS apps cannot read bash environment variables. Look at this question Setting environment variables in OS X? to expose M2_HOME to all applications including IntelliJ. You do need to restart after doing this.

like image 107
Amir Raminfar Avatar answered Sep 29 '22 11:09

Amir Raminfar


type in Terminal:

$ mvn --version 

then get following result:

Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 16:51:28+0300) Maven home: /opt/local/share/java/maven3 Java version: 1.6.0_65, vendor: Apple Inc. Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home Default locale: ru_RU, platform encoding: MacCyrillic OS name: "mac os x", version: "10.9.4", arch: "x86_64", family: "mac" 

here in second line we have:

Maven home: /opt/local/share/java/maven3 

type this path into field on configuration dialog. That's all to fix!

like image 34
flutesa Avatar answered Sep 29 '22 10:09

flutesa