Maven error: Could not find or load main class org

2019-01-03 02:19发布

I have installed a latest maven-3.0.4 on Windows 7:
The installation details are as follows:
Installation Path :

C:\apache-maven-3.0.4  

Environment Variables are:

M2_HOME C:\apache-maven-3.0.4\apache-maven\src  
JAVA_HOME C:\Program Files\Java\jdk-1.7.0_04  

Path variables added are:

%M2_HOME%\bin;%JAVA_HOME%\bin;

In the command window it shows it like this:

C:\>java -version  
java version "1.7.0_04"  
Java(TM) SE Runtime Environment (build 1.7.0_04-b22)  
Java HotSpot(TM) Client VM (build 23.0-b21, mixed mode, sharing)  
C:\>mvn -version  
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher  

This is the only version on maven installed on my PC and the solution given on many blogs referring to the deletion of the previous M2_HOME environment variable is not valid.

I have read and tried all the solutions given at blogs such as :

but still not able to get to it. What I might be missing in this whole thing? Thanks in advance.

26条回答
爷的心禁止访问
2楼-- · 2019-01-03 02:53

I had a problem with surefire plugin itself. Going back to version 2.6 worked for me. Version 2.18/20/22.1 gave me the error. Now I tried version 3.0.0-M1 of surefire plugin and it works.

So something is wrong in surefire plgin between version 2.6 and 3.0.0. I assume there is something hardcoded as default which should not.

查看更多
一纸荒年 Trace。
3楼-- · 2019-01-03 02:54

I had the same issue. I have Windows xp box and when I would type mvn -version at the command line prompt I got the dreaded error message

"Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher"

I confirmed that my M2_HOME variable was set to the path where Maven was installed on pc and that the echo %path% confirmed that Maven was in my path.

I have been searching for a solution for hours when I stumbled on to my solution (I say my solution because I know this probably won't be the solution for everyone that is getting the same error).

I copied the path that was assigned to my M2_HOME variable. I opened a cmd window and typed cd and pasted the path I got from my M2_HOME variable. At that point I knew that the path was correct because the path was displayed in the window. At this point I entered the dir command and to my surprise, I got the error File Not Found.

I went to that path via Explorer and sure enough there were files present. I noticed that the folders were faded out, but I could access them and see the files within each folder (I have admin rights on my pc). I looked at the properties of the parent folder for Maven and saw that the Hidden box was checked. I removed the check and applied and tried my dir command again with success.

Next I tried the mvn –version command again, but this time I got back the expected results.

C:\>mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: C:\Program Files\apache-maven-3.0.3
Java version: 1.5.0_16, vendor: Sun Microsystems Inc.
Java home: C:\Java\jdk1.5.0_16\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"

Finally I created a jar and war file and my web app ran successfully on my local Tomcat.

I hope this helps some of you out there.

查看更多
够拽才男人
4楼-- · 2019-01-03 02:55

The solution for later versions of Maven is straight-forward. I am on OS X ElCap, 10.11.6 and upgraded to Maven 3.3.9. I had the same problem with error "Could not find ...org.codehaus.plexus...". The link provided here offered the solution in a comment by McKamey - simply delete M2_HOME (unset M2_HOME). Once I tried that, it all worked as expected.

This can be confirmed by visiting the Maven install page: "Add the bin directory of the created directory apache-maven-3.3.9 to the PATH environment variable" -- no mention of M2_HOME or M3_HOME at all.

查看更多
走好不送
5楼-- · 2019-01-03 02:55

It look like that you have installed Source files(Because src only comes in Source Files and we don't need it). Try to install Binary Files from there. And then set environment variables as described there. This worked for me. And I am sure it will also work for you.

查看更多
男人必须洒脱
6楼-- · 2019-01-03 02:57

I hit this problem too, and found this article. 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. Hope this helps.

Note: Please delete M2_HOME, if already set. Eg: unset M2_HOME

查看更多
趁早两清
7楼-- · 2019-01-03 02:58

You should change the location of the M2_HOME into the following:

set M2_HOME=C:\apache-maven-3.0.4\apache-maven

Furthermore the installation of the JDK looks more a JRE instead of JDK. For Maven you need JDK and NOT JRE.

查看更多
登录 后发表回答