Maven error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher

匿名 (未验证) 提交于 2019-12-03 02:03:01

问题:

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.

回答1:

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



回答2:

I was having this same problem and was able to resolve it by carefully redoing the Environment Variables:

  • M2_HOME
  • M2
  • JAVA_HOME

Also, I made them all System Variables, not User Variables like the Maven instructions say. When you

echo %Path% 

Make sure you can see the %M2% and %JAVA_HOME% variables completely expanded, i.e. :

C:\Users\afairchild>echo %Path% C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\bin;C:\Program Files\Java\jdk1.7.0_09\bin; [etc] 


回答3:

Had this issue on two different Ubuntu 12.04 installs, despite the installs being done by apt-get. Issue was M2_HOME.

Fixed with:

export M2_HOME=/usr/share/maven 


回答4:

Even though the question is answered I would like to add that, if you are getting the above mentioned error, be sure that you have downloaded the Binary file.

The source file should only be downloaded if you are an advanced user and that you know how to deal with it.

I have had quite a share of people downloading the wrong file, seniors and juniors



回答5:

It sounds like you installed (extracted) the source files instead of the binaries based on your path information. Try installing the binaries instead and following the other posters answer.



回答6:

Well, I had this problem and after seeing this post and particularly khmarbaise answer I noticed that M2_HOME was

D:\workspace\apache-maven-3.1.0-bin\apache-maven-3.1.0\bin 

and then I chaged it to

D:\workspace\apache-maven-3.1.0-bin\apache-maven-3.1.0 

I would like to mention that I use windows 7 (x64)



回答7:

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.



回答8:

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.



回答9:

I came across a similar problem on my mac OSX. After a series of trial and error attempts I finally resolved it.

My ~/.bash_profile looked like this

export M2_HOME=/Users/xyz/maven-3.x/bin export PATH=$PATH:$M2_HOME 

and when I tried to echo M2_HOME from the terminal, it showed me the correct path but when I tried to fire any maven command like mvn clean or mvn install, it always gave the same problem

Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher

I solved this issue by changing my M2_HOME to this

export M2_HOME=/Users/xyz/maven-3.x export PATH=$PATH:$M2_HOME/bin 

And voila ! It started working ! Just by moving the position of /bin from M2_HOME to in front of the PATH



回答10:

I believe this error caused because of downloading SRC instead of BINARY from Maven site. Please make sure to download Binary zip.

Because the below path, you will get only when you download SRC:

M2_HOME C:\apache-maven-3.0.4\apache-maven\src



回答11:

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



回答12:

Besides what @khmarbaise has pointed out, I think you have mistyped your JAVA_HOME. If you have installed in the default location, then there should be no "-" (hyphen) between jdk and 1.7.0_04. So it would be

JAVA_HOME C:\Program Files\Java\jdk1.7.0_04  


回答13:

For other people who might run into this, don't forget to check ~/.mavenrc for M2_HOME or JAVA_HOME settings.



回答14:

Try to download binary zip (for ex. Maven 3.0.5 (Binary zip)) instead of complete source in official maven site. Also make sure that command line recognizes java and javac commands. I noticed that Maven Source zip didn't include any libraries at lib folder however Binary zip had them + in boot folder it had plexus-classworlds-2.4.jar. Perhaps the problem was with the absence of these libraries. Anyway it helped me so my M2_HOME is: C:\Program Files\Java\apache-maven-3.0.5 and at PATH I put: C:\Program Files\Java\apache-maven-3.0.5\bin.



回答15:

I find this issue in my centOS is caused by "Oracle Java is replace by gcj", after change default java to "Oracle Java", the issue is resolved.

alternatives --config java  There are 2 programs which provide 'java'.    Selection    Command ----------------------------------------------- *  1           /usr/lib/jvm/jre-1.5.0-gcj/bin/java  + 2           /usr/java/jdk1.7.0_67/bin/java 


回答16:

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.



回答17:

I think you download the wrong version. I meet this problem just now, no method work after searching and searching. Finally, I found that maven I downloaded is Source zip archive. After I change to Binary zip archive, everything go to be fine.



回答18:

Just make sure you've downloaded Binary zip archive(apache-maven-3.5.0-bin.zip) instead of Source zip archive. Then add the bin directory of the created directory apache-maven-3.5.0 to the PATH environment variable.



回答19:

Exactly the same error may appear even with correct environment variable settings, if you copy ONLY bin directory to the installation directory. It make which work finely, and novices get stuck.



回答20:

Me too faced the similar issue. But in my case I used apache-maven-3.3.3-src folder in path variables. Later I corrected those with correct path of folder apache-maven-3.3.3-bin. This resolved the issue. Am not telling that is the same error reported here but this way also you can get this error and rectify it. That is what I am trying to say here.



回答21:

This is a common issue while setting up Maven. All you need to do is the below :-

  1. M2_HOME :- D:\apache-maven-2.0.11
  2. M2 :- D:\apache-maven-2.0.11\bin
  3. Path :- Append it with ;%M2%

M2_HOME & M2 :- need to be declared as System variables and not as USER / ADMIN Variables.

Path :- This can be the System Variable OR the USER / ADMIN variable [PATH]. Preferably System Variable.

Once you carefully do the setting of these 3 variable, you can verify Maven's installation as below.

On CMD Prompt :-


C:\Documents and Settings\ADMIN>mvn --version


Output :-


Apache Maven 2.0.11 (r909250; 2010-02-12 11:25:50+0530) Java version: 1.6.0_22 Java home: C:\Program Files\Java\jdk1.6.0_22\jre Default locale: en_US, platform encoding: Cp1252 OS name: "windows xp" version: "5.1" arch: "x86" Family: "windows"

Thanks.



回答22:

Next to the maybe useful, but maybe too symptomatic answers, here is one which tries to help to find the cause of the problem.

Maven is a command-line java tool. That means, it is not a standalone binary, it is a collection of java .jars, interpreted by a jvm (java.exe on windows, java on linux).

The mvn command, is a script. On windows, it is a script called mvn.cmd and on linux, it is a shell script. Thus, if you write: mvn install, what will happen:

  1. a command interpreter (/bin/sh or cmd.exe) is called for the actual invoking script
  2. this script sets the needed environment variables
  3. and finally, it calls a java interpreter with the the required classpath which contain the maven functionality.

The problem is with (2). Fortunately, this script is simply, very simple. For a java programmer it shouldn't be a big trouble to debug a script around 20 lines, even if it is a little bit alien language.

On linux, you can debug shellscripts giving the -x flag to your shell interpreter (which is most probably bash). On windows, you have to find some other way to debug a cmd.exe script. So, instead of mvn install, give the command bash -x mvn install.

The result be like:

+ '[' -z '' ']' + '[' -f /etc/mavenrc ']' + '[' -f /home/picsa/.mavenrc ']' + cygwin=true + darwin=false 

...not so many things...

+ MAVEN_PROJECTBASEDIR='C:\peter\bin' + export MAVEN_PROJECTBASEDIR + MAVEN_CMD_LINE_ARGS=' ' + export MAVEN_CMD_LINE_ARGS + exec '/cygdrive/c/Program Files/Java/jdk1.8.0_66/bin/java' -classpath 'C:\peter/boot/plexus-classworlds-*.jar' '-Dclassworlds.conf=C:\peter/bin/m2.conf' '-Dmaven.home=C:\peter' '-Dmaven.multiModuleProjectDirectory=C:\peter\bin' org.codehaus.plexus.classworlds.launcher.Launcher Fehler: Hauptklasse org.codehaus.plexus.classworlds.launcher.Launcher konnte nicht gefunden oder geladen werden 

At the end, you can easily test, which environment variable gone bad, and you can very easily fix your script (or set it what is needed).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!