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

2020-08-24 02:45发布

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!

标签: java maven
8条回答
\"骚年 ilove
2楼-- · 2020-08-24 03:19

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 .

查看更多
老娘就宠你
3楼-- · 2020-08-24 03:20

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

查看更多
姐就是有狂的资本
4楼-- · 2020-08-24 03:21

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.

查看更多
Fickle 薄情
5楼-- · 2020-08-24 03:27

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

查看更多
Anthone
6楼-- · 2020-08-24 03:28

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
查看更多
Rolldiameter
7楼-- · 2020-08-24 03:37

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.

查看更多
登录 后发表回答