Maven: mvn --version java.lang.ClassNotFoundException

*爱你&永不变心* 提交于 2019-12-24 00:48:26

问题


I have just installed new Maven into my new Fedora 17 64bit.

Details:

java -version

java version "1.6.0_32"
Java(TM) SE Runtime Environment (build 1.6.0_32-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.7-b02, mixed mode)

javac -version

javac 1.6.0_32

echo $JAVA_HOME

/usr/java/jdk1.6.0_32

echo $JRE_HOME

/usr/java/jdk1.6.0_32/jre

echo $M2_HOME

/usr/local/maven/apache-maven-3.0.4

echo $M2

/usr/local/maven/apache-maven-3.0.4/bin

echo $PATH

/usr/local/maven/apache-maven-3.0.4/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/usr/java/jdk1.6.0_32/bin:/home/bujaka/.local/bin:/home/bujaka/bin

which mvn

/usr/local/maven/apache-maven-3.0.4/bin/mvn

But mvn -version throws java.lang.ClassNotFoundException.

java.lang.ClassNotFoundException: org.apache.maven.cli.MavenCli
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(Launcher.java:145)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:267)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)                                                    
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)                                          
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

P.S. I installed maven from apache site (not from fedora repos)


回答1:


MavenCli class is in maven-embedder. Are you behind a proxy?

  <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
    </proxy>
  </proxies>
  ...
</settings>

@See Maven Proxy Settings




回答2:


thanks user1436170, your last comment did the job for me as well:

/lib catalog was empty in maven.tar.gz archive.

When opening via krusader, lib folder in tar.gz file it was empty, but it contains jars when opening via ark.

Anyway zip works.




回答3:


I just came across this same issue. Bujaka's comment and Peter Butkovic's answer get at the issue, but for the record here's my take on it and the solution I used.

I don't know what causes this, but sometimes the entire content of the /lib folder in your maven installation directory can become empty. This may be the case when you get this error.

If you check your /lib folder and find that it is not empty, it is still possible (although unlikely) that a crucial file somehow got deleted.

If your maven installation used to work find and only started acting up recently, then the zipped archive you used was probably fine. Here's what to do:

  1. Rename your installation directory (or if you're brave, just delete it).
  2. Get the original zipped archive. (If you're like me, it's still somewhere in your increasingly cluttered downloads folder. If not you'll have to re-download it.)
  3. Unzip said archive into the location of your original installation directory (which you either renamed or deleted).

Your maven installation should now work again.



来源:https://stackoverflow.com/questions/10889445/maven-mvn-version-java-lang-classnotfoundexception

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