Programmers learn & share
0 votes
96 views

Problem :

I am stuck with following Maven issue.

Error: could not find or load main class org.codehaus.plexus.classworlds.launcher.launcher      

My Maven was working fine till last week after that I do not know what went wrong with it now it gives me the error I have tried replacing M2_HOME path with M3_HOME and also MAVEN_HOME. But nothing is working for me. I am using OS X. Following is the output of few maven commands. Let me know if you know the solution for my error:

$ mvn

Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher

$ which mvn

/Library/Maven-3.3.3/bin/mvn

$ echo $M2_HOME

/Library/Maven-3.3.3

$ echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home

$ which java

/usr/bin/java

$ /Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java -version

java version "1.7.0_75"

Java(TM) SE Runtime Environment (build 1.7.0_75-b13)

Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

$ echo $PATH

/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Tomcat/bin:/Library/Maven-3.3.3/bin

$ java -version

java version "1.7.0_75"

Java(TM) SE Runtime Environment (build 1.7.0_75-b13)

Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

by (7.5k points)   | 96 views

2 Answers

0 votes

Solution :

Remove your M2_HOME as the environment variable, as it is already set by the mvn script. The only things remaining are: To add apache-maven-3.x.x/bin to your path and set JAVA_HOME as environment variable. And also no need to add %JAVA_HOME%/bin to your path

Please run mvn -v from /Library/Maven-3.3.3/bin/ folder first to confirm your installation is correct. Also try to run mvn with xtrace info and also verify the command line built up by Maven. I assume you get an unexpected class path argument value.

by (36.1k points)  
0 votes

Solution:

 For Maven3, changing my environment variable name from M2_HOME to M3_HOME did the trick. I am on a Mac running OSX 10.9 with JDK 1.7.

Please remove M2_HOME as environment variable, it is already set by the mvn script. The only things you need to do is: add apache-maven-3.x.x/bin to your path, set JAVA_HOME as environment variable. So no need to add %JAVA_HOME%/bin to your path

Try to run mvn -v from /Library/Maven-3.3.3/bin/ folder first to confirm the installation is correct. Try to run mvn with xtrace info (tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html) and verify the commandline built up by Maven. I assume you get an unexpected classpath argument value.

EDIT : Note this is for Mac users

M2_HOME needs to be removed from the PATH. By default, your PATH might be picked up from one of the following files (for me, it was in ~/.profile).

Code:

/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist

It might look something like this:

export M2_HOME=/Applications/apache-maven-3.2.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH

Remove the M2_HOME variables, and any dependencies (in the example, the M2 variable uses M2_HOME, so remove that, and the line after which uses $M2) where ever it shows up.

Just to give more info on how this file is used, you can keep appending whatever location you want to include in the path

For instance, if you want to include /User/batman/google-sdk into path, then adding the below line to the end of the file will append /Users/batman/google-sdk (in your case whatever the location of the folder is), to the PATH.

export PATH=$PATH:/Users/batman/google-sdk.

But make sure the PATH already has some info before the above line.

by (11.2k points)  
2,227 questions
2,734 answers
59 comments
241 users