24

I am having difficulties installing Maven.

I have set all the enviromental variables according to this: http://maven.apache.org/download.html

Although I am using windows 7, when I try and run the command mvn --version, I get, mvn is not recognized as an internal or external command etc.

When I run it from within src\bin, I get the error:

Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher 
at java.net.URLClassLoader$1.run<URLClassLoader.java:202>
at java.security.AccessController.doPrivleged(Native Method) 
...etc

then:

Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher.
om-nom-nom
  • 60,231
  • 11
  • 174
  • 223
JWK
  • 241
  • 1
  • 2
  • 3
  • The first problem (`...not recognized as an internal or external command...`) is a ***PATH*** problem in Windows. The second problem (`...ClassNotFoundException...`) is a ***Classpath*** problem in Java. Voting to close on the first problem as a duplicate. After you fix the path problem, come back with your other problems. – jww Sep 09 '14 at 11:46
  • 1
    It look like that you have installed Source files. Try to install **Binary Files** from there. [link](https://maven.apache.org/download.cgi) And then set environment variables as described there. [link](http://www.mkyong.com/maven/how-to-install-maven-in-windows/) – Hammad Hassan Aug 20 '15 at 06:25

12 Answers12

48

Check that you don't have an M2_HOME environment variable.

spoulson
  • 20,523
  • 14
  • 72
  • 101
andhdo
  • 516
  • 4
  • 2
  • 8
    Similar issue: I upgraded from maven 2 to maven 3 on OS X, using MacPorts ("port install maven3") - I got the same error. Removing the M2_HOME env variable and removing it from the path (as set in in my ~/.bash_profile) solved my issues. – PapaFreud Apr 17 '12 at 13:34
  • 5
    Thanks, I may add that to remove M2_HOME variable, you need to execute in terminal: unset M2_HOME – darkyndy Aug 14 '14 at 06:53
  • 1
    For brew based install on Mac: Checked the symbolic link for mvn under following directory /usr/local/bin/ and add the correct maven version with the following export export M2_HOME="/usr/local/Cellar/maven/3.3.3/libexec" export PATH=$PATH:$M2_HOME/bin – Gajen Sunthara Sep 07 '15 at 20:36
27

I ended up on this question with the same problem, however, I had committed an elementary mistake of downloading the apache-maven-..*-src.zip instead of the apache-maven-..*-bin.zip

Once I realised that mistake, it was smooth sailing as soon as I corrected it. I suppose the instructions on the download page should be more than adequate

shekhar karande
  • 271
  • 3
  • 2
11

All you should need to do to install and use maven:

1) Download maven 3. The ZIP should be fine. Install it in a known place; I use c:\tools\ as the parent directory but your mileage may vary.

2) Set your PATH to point to the bin directory in the installation directory. If Maven is in c:\tools\maven-3.0.3 (as it is on my system), you'd add c:\tools\maven-3.0.3\bin to PATH:

set PATH=%PATH%;c:\tools\maven-3.0.3

You may also want to set MVN_HOME:

set MVN_HOME=c:\tools\maven-3.0.3

3) start a new command shell (cmd.exe). mvn should work; if not, you've skipped something here or something's badly wrong in your configuration.

Joseph Ottinger
  • 4,711
  • 1
  • 20
  • 23
10

blanking out M2_HOME worked for me on Ubuntu. Can test with just: 'export M2_HOME='

greta
  • 121
  • 1
  • 4
3

Your first problem is because you do not have maven in your PATH. The second problem is what I had. I had both Maven 2 and 3 on my computer and even though I removed Maven 2 links from my PATH, it was still interfering with my new Maven.

You need to remove or rename the system variable M2_HOME. 1. Right click My Computer -> Properties 2. Advanced system settings 3. Environment Variables 4. Rename or delete M2_HOME

Maverikki
  • 71
  • 6
2

I setup M2_HOME like this:

export M2_HOME="~/app/apache-maven-3.1.1"

and saw the same exception:

Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher`. 

I changed to use absolute path and it worked:

export M2_HOME="Users/myaccount/app/apache-maven-3.1.1"

In my case, the M2_HOME env variable wasn't the problem. I think that java and/or mvn startup script doesn't expand the tilde in classpath cmd line args.

Upgradingdave
  • 12,236
  • 10
  • 58
  • 69
1

I got the same error

In my case configuration which generate error

export M2_HOME="/home/ashoka/apache-maven-3.0.4/bin/"

PATH=$M2_HOME/bin:$PATH

Working configuration

export M2_HOME="/home/ashoka/apache-maven-3.0.4/"

PATH=$M2_HOME/bin:$PATH

Ashok Kumara

Himanshu
  • 4,224
  • 16
  • 28
  • 36
Ashok
  • 699
  • 5
  • 3
1

This is a question from long ago but recently i encountered this problem. In my case it was because i had M2_HOME set from a previous installation from months ago. I just unset the variable and after that was good to go.

Sai
  • 3,629
  • 1
  • 23
  • 25
0

Some people seem to have trouble with adding Maven bin folders to the System PATH vs the User PATH. You could try defining your environment under your User variables, but this would be more of a workaround than a solution.

PATH=%PATH%;%JAVA_HOME%\bin;%JRE_HOME%\bin;%MAVEN_HOME%\bin

You can diagnose these access errors with Rapid Environment Editor, which will tell you if certain PATH locations are invalid or inaccessible to you.

Rosa
  • 632
  • 6
  • 20
0

"mvn is not recognized as an internal or external command etc." means you haven't set your environment variable in windows. Read the whole http://maven.apache.org/download.html :-)

Karl-Bjørnar Øie
  • 5,374
  • 22
  • 30
0

Do you have maven 2 also installed? I found one link in searching, see if it helps http://blogs.oracle.com/sreekanth/entry/java_lang_noclassdeffounderror_org_codehaus

and also double check your environment variables to make sure you have set all the variables mentioned in the doc.

For this error "mvn is not recognized as an internal or external command", add src/bin folder in 'path' environment variable.

Reddy
  • 8,219
  • 9
  • 50
  • 72
0

Like Joseph Ottinger said, you have to put Maven installation directory to your PATH environment variables or User variables. You can edit user variables by running command "rundll32 sysdm.cpl,EditEnvironmentVariables" without quotes.

First add new variable called MAVEN_HOME and for it's value Mavens installation directory ie. c:\tools\maven-3.0.3\ then edit PATH variable and add end of the value ;%MAVEN_HOME%\bin (notice semicolon)

After re-login or opening new command prompt mvn command should work perfectly.

Timii
  • 234
  • 4
  • 11