0

I am trying to download Maven on my mac OSX yosemite. I tried to download it manually and I wrote this in the .bash_profile

export M2_HOME=/usr/local/apache-maven-3.2.5
export PATH=$PATH:$M2_HOME/bin

I also used the source command and I still get this error when I try to execute mvn command:

-bash: mvn: command not found

I tried to use an alternative solution to solve the problem, which is: brew install maven

But the problem is that brew is actually using an deadlink URL to download maven, thus, I was unable to solve the problem using brew!

In addition, I tried to search for JAVA_HOME but I couldn't locate it even though I have java 6,7, and 8 installed on my mac.

can someone please help me with this?

I tried to execute sh mvn and got this error message:

Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

rullzing
  • 622
  • 2
  • 10
  • 22

3 Answers3

3

Homebrew has updated the Maven formula.

Use brew update and then try brew install maven again.

Eric
  • 31
  • 1
0

export PATH="$PATH:/usr/local/apache-maven-3.2.5/bin"

mvn executable is not in /usr/local/apache-maven-3.2.5/ but rather in /usr/local/apache-maven-3.2.5/bin subfolder.

  1. check that /usr/local/apache-maven-3.2.5/bin/mvn actually exists
  2. check (e.g. with ls -l) that its permissions contain executable (x) flag. Use chmod 0755 /usr/local/apache-maven-3.2.5/bin/mvn it they don't.
  3. In any case /usr/local/apache-maven-3.2.5/bin/mvn is a shell script, so you may try to run it with shell directly: sh /usr/local/apache-maven-3.2.5/bin/mvn and see if it runs indeed. If it still can't be run, use sh -x /usr/local/apache-maven-3.2.5/bin/mvn to see exactly the line where it fails.
user3159253
  • 16,836
  • 3
  • 30
  • 56
  • 1 and 2 look fine, however, I got an exception error after executing sh mvn, I will post the error in the question. – rullzing Jan 04 '15 at 00:40
  • Ok, so you have at least two problems with your setup, one with `mvn` shell script and another with java classpath. Let's solve them one by one. – user3159253 Jan 04 '15 at 00:46
  • It does exist: `+ exec /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java -classpath '/usr/local/apache-maven-3.2.5/bin/boot/plexus-classworlds-*.jar' -Dclassworlds.conf=/usr/local/apache-maven-3.2.5/bin/bin/m2.conf -Dmaven.home=/usr/local/apache-maven-3.2.5/bin org.codehaus.plexus.classworlds.launcher.Launcher` – rullzing Jan 04 '15 at 00:56
  • The problematic piece is `-classpath '/usr/local/apache-maven-3.2.5/bin/boot/plexus-classworlds-*.jar'` Likely the expansion isn't occured (in my installation it gets expanded to `-classpath /usr/local/maven3/boot/plexus-classworlds-2.5.1.jar`, notice the precise numbers there. Likely, your M2_HOME is set incorrectly. Unset it completely or at least set to `/usr/local/apache-maven-3.2.5` not `/usr/local/apache-maven-3.2.5/bin` – user3159253 Jan 04 '15 at 01:10
  • I thought it's in bin because this is what I should have in my path? I tried to remove it from the path and re-executed sh -x mvn, however, I still get the same issue even though I now have `-classpath '/usr/local/apache-maven-3.2.5/boot/plexus-classworlds-*.jar'` – rullzing Jan 04 '15 at 01:16
  • check that file `plexus-classworlds-.jar` actually exists in `/usr/local/apache-maven-3.2.5/boot` and is readable by you. – user3159253 Jan 04 '15 at 01:19
  • ops. It turns out that I wasn't installing it in the right path, I don't really know how did this thing happen because I was in /usr/local before (maybe I terminated the terminal and re-opened a new one and forgot about that). Anyway, I've moved the folders to /usr/local and I was able to execute mvn. Thank you very much. – rullzing Jan 04 '15 at 01:44
0

I had the same issues but I got it resolved by adding /bin to $PATH as follows:

export M2_HOME=/Applications/apache-maven-3.6.0/bin:$PATH
export PATH=$PATH:$M2_HOME/bin
Szymon Maszke
  • 22,747
  • 4
  • 43
  • 83
Dinu
  • 1