高手的存在,就是让服务10亿人的时候,你感觉只是为你一个人服务......

异常java.lang.ClassNotFoundException com.google.common.base.Strings

目录

最近开始研究jvm-sandbox,将源码下下来,开始编译,报错了:

java.lang.ClassNotFoundException: com.google.common.base.Strings


具体异常如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Strings
at org.sonatype.nexus.maven.staging.deploy.DeployLifecycleParticipant.getPluginByGAFromContainer(DeployLifecycleParticipant.java:238)
at org.sonatype.nexus.maven.staging.deploy.DeployLifecycleParticipant.getNexusMavenPluginFromContainer(DeployLifecycleParticipant.java:182)
at org.sonatype.nexus.maven.staging.deploy.DeployLifecycleParticipant.getBuildPluginsNexusMavenPlugin(DeployLifecycleParticipant.java:163)
at org.sonatype.nexus.maven.staging.deploy.DeployLifecycleParticipant.afterProjectsRead(DeployLifecycleParticipant.java:95)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:264)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
Caused by: java.lang.ClassNotFoundException: com.google.common.base.Strings
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)

com/google/common/base/Strings类是Guava的包,pom.xml里面配置如下:

1
2
3
4
5
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>

翻看了自己的maven本地仓库,Guava的jar包版本从14.0到27.0,应有尽有,无论怎么修改jar的版本号,一直报上面的错误。

快疯掉了….

一气之下将本地仓库的Guava文件夹全部删掉,重新编译。

竟然成功了!!

花了一上午的时间排查,在此记录一下maven的坑。