11

So I've installed maven with the following details:

Install path:

C:\Program Files\Apache Software Foundation\apache-maven-3.0.3

Env vars:

JAVA_HOME C:\Progra~1\Java\jdk1.6.0_25
M2_HOME C:\Program Files\Apache Software Foundation\apache-maven-3.0.3

User vars:

M2 %M2_HOME%\bin
PATH %JAVA_HOME%\bin;%M2%;

Now, from the command line

C:\>javac -version
javac 1.6.0_25

C:\>mvn -version
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/c
lassworlds/launcher/Launcher

Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.lau
ncher.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.loadClss(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher
.  Program will exit.

I've been insulated from the command line build details for Java thus far thanks to Eclipse, but it looks like it's having problems with finding the plexus-classworlds-2.4.jar in the /boot dir. Should I need some additional path info?

Thanks!

jchristof
  • 2,794
  • 7
  • 32
  • 47
  • Just as a sanity check, to be sure you're using the maven you just installed: what's the output of `mvn --version`? I've run into strangeness like this with 2 versions of maven installed. – Upgradingdave Nov 15 '11 at 16:08
  • 1
    It's likely not the issue, but in general, I recommend avoiding paths with spaces. (Or tildes, for that matter.) I don't see the issue locally, though. – Dave Newton Nov 15 '11 at 16:13
  • @Dave - I formatted the above better. mvn -version is what produces this output. – jchristof Nov 15 '11 at 16:19
  • @ Dave N - yeah, Apache recommends installing into that path. It seems to be ok in terms of finding mvn though. since c:\mvn -version at least finds mvn. – jchristof Nov 15 '11 at 16:39
  • Possibly related to http://stackoverflow.com/questions/6823940/error-when-trying-to-see-mvn-version-in-cmd – Raghuram Nov 16 '11 at 08:14

9 Answers9

4

I had similar by having mvn.bat for maven2 in other part of PATH. So check carefully all directories of your PATH variable.

kan
  • 28,279
  • 7
  • 71
  • 101
  • at the risk of providing too much info:PATH= C:\Projects\Mobile\Tools\android-sdk-windows\tools; C:\Projects\Mobile\Tools\android-sdk-windows\platform-tools; C:\Projects\Mobile\Tools\ant\bin; C:\Windows\system32; C:\Windows; C:\Program Files\Perforce; C:\Program Files\Java\jre6\bin; C:\Program Files\TortoiseSVN\bin; C:\Progra~1\Java\jdk1.6.0_25\bin; C:\Program Files\Apache Software Foundation\apache-maven-3.0.3\bin; – jchristof Nov 15 '11 at 16:54
  • 7
    This is a helpful answer. It made me notice that M2_HOME was still pointing to my old maven installation, which causes the above error (in my case) – qwerty Mar 27 '12 at 05:04
  • I had Path having 2 JDK folders. M2_Home was pointing to older version of maven. Fixed these issues and it started working. – Mir Kazim Ali Tabrez Apr 20 '21 at 06:18
2

I was able to resolve my issue with following when

export JAVA_HOME=/blah/blah
export M2_HOME=/usr/local/maven   
export M2=M2_HOME/bin

I was able to figure out looking at the folder name, it was 3.2.1

Perhaps, I didn't read document, but here's my answer to this problem.

export JAVA_HOME=/blah/blah
export M3_HOME=/usr/local/maven   
export M3=M2_HOME/bin

My java is 7. Hope this helps some people with Maven 3 instead of M2.

Jerry H
  • 105
  • 2
  • 7
1

even I face the same issue and then i changed echo off to echo on in mvn.bat and find out that my maven package was not installed properly and boot folder under c:/maven/maven3.0.3 is missing , i copied the missing folder and it worked :)

mayank
  • 11
  • 1
1

Try this:

unset M2_HOME
source .bash_profile

.bash_profile:

...
export M2_HOME=$(/Users/camel/apache-maven-2.2.1)
export PATH=$PATH:$M2_HOME/bin
...

This work for my Mac(os x ver 10.11) when I use maven2 after maven3.

CamelTM
  • 1,225
  • 12
  • 17
0

I resolved this problem by removing all JRE/JDK then reinstalling the needed JDK and removing all spaces from folders path.

C:\dev\jdk
C:\dev\maven3.0.4
C:\dev\project\myProject
c:\dev\eclipse
Heetola
  • 5,791
  • 7
  • 30
  • 45
0

You probably need to set MAVEN_HOME plus M2_HOME . Both with the same path . Make sure that the variables must be set so well and try again. After trying to install version 7.8 of java because Version 6 may not be compatible .

NB : set maven in path , for instance on my Mac I have a .profile with the following settings : export JAVA_HOME = $ ( Library / Java / JavaVirtualMachines / jdk1.8.0_101.jdk / Contents / Home ) export PATH = / Users / alessandropioardizio / Desktop / SDK / apache - maven - 3.1.1 / bin : $ PATH

Let me know if it works .

pioardi
  • 181
  • 2
  • 7
0

I resolved mine by upgrading my maven from apache-maven-3.3.9 to apache-maven-3.5.4. And finally, Modify my System variables to apache-maven-3.5.4: Add both M2_HOME

M2_HOME :: C:\apache-maven-3.5.4

JAVA_HOME : C:\Program Files\Java\jdk1.8.0_101

TobyFagboh
  • 50
  • 6
0

you have to delete M2_HOME and try again

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 09 '23 at 05:18
0

Is there a C:\mvn.bat?

On Windows, the current folder is always in the PATH.

[EDIT] The error can have several reasons: The version of mvn.bat doesn't fit the rest of the code, or the libraries are corrupt.

To get one step further, change the line @echo off in mvn.bat to @echo on and run the script again. It will then print each command as it is executed. Search the output for %CLASSWORLDS_JAR%

Make sure all JARs mentioned in %CLASSWORLDS_JAR% exist and are OK.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820