Problems setting up Maven [duplicate]

2019-01-21 19:54发布

This question already has an answer here:

I am having difficulties installing Maven.

I have set all the enviromental variables according to this: http://maven.apache.org/download.html

Although I am using windows 7, when I try and run the command mvn --version, I get, mvn is not recognized as an internal or external command etc.

When I run it from within src\bin, I get the error:

Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher 
at java.net.URLClassLoader$1.run<URLClassLoader.java:202>
at java.security.AccessController.doPrivleged(Native Method) 
...etc

then:

Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher.

12条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-21 20:08

Do you have maven 2 also installed? I found one link in searching, see if it helps http://blogs.oracle.com/sreekanth/entry/java_lang_noclassdeffounderror_org_codehaus

and also double check your environment variables to make sure you have set all the variables mentioned in the doc.

For this error "mvn is not recognized as an internal or external command", add src/bin folder in 'path' environment variable.

查看更多
聊天终结者
3楼-- · 2019-01-21 20:11

Check that you don't have an M2_HOME environment variable.

查看更多
一夜七次
4楼-- · 2019-01-21 20:11

I setup M2_HOME like this:

export M2_HOME="~/app/apache-maven-3.1.1"

and saw the same exception:

Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher`. 

I changed to use absolute path and it worked:

export M2_HOME="Users/myaccount/app/apache-maven-3.1.1"

In my case, the M2_HOME env variable wasn't the problem. I think that java and/or mvn startup script doesn't expand the tilde in classpath cmd line args.

查看更多
冷血范
5楼-- · 2019-01-21 20:11

"mvn is not recognized as an internal or external command etc." means you haven't set your environment variable in windows. Read the whole http://maven.apache.org/download.html :-)

查看更多
爷、活的狠高调
6楼-- · 2019-01-21 20:12

All you should need to do to install and use maven:

1) Download maven 3. The ZIP should be fine. Install it in a known place; I use c:\tools\ as the parent directory but your mileage may vary.

2) Set your PATH to point to the bin directory in the installation directory. If Maven is in c:\tools\maven-3.0.3 (as it is on my system), you'd add c:\tools\maven-3.0.3\bin to PATH:

set PATH=%PATH%;c:\tools\maven-3.0.3

You may also want to set MVN_HOME:

set MVN_HOME=c:\tools\maven-3.0.3

3) start a new command shell (cmd.exe). mvn should work; if not, you've skipped something here or something's badly wrong in your configuration.

查看更多
走好不送
7楼-- · 2019-01-21 20:15

blanking out M2_HOME worked for me on Ubuntu. Can test with just: 'export M2_HOME='

查看更多
登录 后发表回答