1
votes

I recently upgraded to Yosemite and my maven stopped working. I figured that was because my environment variables were not set, so I followed this post and created an environment.plist file.

Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"     "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>my.startup</string>
  <key>ProgramArguments</key>
  <array>
    <string>sh</string>
    <string>-c</string>
    <string>
        launchctl setenv M2_HOME /Applications/dev/apache-maven-2.2.1
        launchctl setenv M2 /Applications/dev/apache-maven-2.2.1/bin
        launchctl setenv JAVA_HOME $(/usr/libexec/java_home)
        launchctl setenv PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$(/usr/libexec/java_home):/Applications/dev/apache-maven-2.2.1/bin
    </string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>   

But I still get command not found in for Maven, and for some reason $PATH is not set, others are

MAC-R4498:~ r4498$ mvn --version
-bash: mvn: command not found

MAC-R4498:~ r4498$ echo $M2_HOME
/Applications/dev/apache-maven-2.2.1

MAC-R4498:~ r4498$ echo $JAVA_HOME
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

MAC-R4498:~ r4498$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

So I added $PATH to the ~/.bash_profile

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:$(/usr/libexec/java_home):/Applications/dev/apache-maven-2.2.1/bin"

And mvn started working through the terminal

MAC-R4498:~ r4498$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home:/Applications/dev/apache-maven-2.2.1/bin

MAC-R4498:~ r4498$ mvn --version
Apache Maven 2.2.1 (r801777; 2009-08-06 14:16:01-0500)
Java version: 1.6.0_65
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x" version: "10.10.3" arch: "x86_64" Family: "mac"

But when I run any maven command from eclipse, I get this

enter image description here

Does anyone know what I am missing?

2
After you made the change the to PATH, did you restart Eclipse?user489041
What does which mvn return?nitind
Returned /Applications/dev/apache-maven-2.2.1/bin/mvnRicha

2 Answers

2
votes

This took forever to figure out.

All I had to do was go to Eclipse->Preferences ->Maven->Installations and add a path to my maven directory.

enter image description here

0
votes

Open eclipse from terminal it works for me.