New Maven install: mvn -version java.lang.ClassNot

2020-08-24 03:00发布

问题:

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!

回答1:

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



回答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.



回答3:

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 :)



回答4:

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.



回答5:

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.



回答6:

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


回答7:

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 .



回答8:

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



标签: java maven