【问题标题】:ClassNotFoundException using apache-common-lang3ClassNotFoundException 使用 apache-common-lang3
【发布时间】:2015-05-16 17:49:54
【问题描述】:

我正在使用 Elasticsearch Jest 客户端编写我自己的客户端应用程序。

我不断得到这个
java.lang.ClassNotFoundException: org.apache.commons.lang3.StringUtils

即使我已经在构建过程中包含了所有 JAR。

采取的措施:

  1. 禁用 maven 并手动添加所有 JARS
  2. 在 3.3.2 之上添加了 apache-common-lang-2.6
  3. 清理/重启 eclipse

什么都没有:(

错误截图:

错误信息:

Exception in thread "main" java.lang.NoClassDefFoundError:       
    org/apache/commons/lang3/StringUtils

    at io.searchbox.action.AbstractAction.buildURI(AbstractAction.java:171)
    at    io.searchbox.action.AbstractDocumentTargetedAction.buildURI(AbstractDocumentTarg     etedAction.java:40)
    at io.searchbox.core.Index.<init>(Index.java:23)
    at io.searchbox.core.Index.<init>(Index.java:15)
    at io.searchbox.core.Index$Builder.build(Index.java:63)
at   
   
Kinnetics.KinneticsElasticsearchClient.indexParameter(KinneticsElasticsearchClient.java:54)
at Kinnetics.ManagementWrapper.main(PredictoModule.java:74)
at Kinnetics.PredictoModule.main(PredictoModule.java:28)
Caused by: java.lang.ClassNotFoundException:     org.apache.commons.lang3.StringUtils
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 8 more

verbose:class output:
             Line 6: C:\Users\Eitan\workspace\SelfAnomalyDetector - ver7\JARs For   Jest\commons-lang-2.6.jar;
            Line 7: C:\Users\Eitan\workspace\SelfAnomalyDetector - ver7\JARs For Jest\commons-lang-2.6-javadoc.jar;
            Line 8: C:\Users\Eitan\workspace\SelfAnomalyDetector - ver7\JARs For Jest\commons-lang-2.6-sources.jar;
            Line 9: C:\Users\Eitan\workspace\SelfAnomalyDetector - ver7\JARs For Jest\commons-lang3-3.3.2.jar;
            Line 10: :\Users\Eitan\workspace\SelfAnomalyDetector - ver7\JARs For Jest\commons-lang3-3.3.2-javadoc.jar;
            Line 11: C:\Users\Eitan\workspace\SelfAnomalyDetector - ver7\JARs For Jest\commons-lang3-3.3.2-sources.jar;
             Line 64: C:\Users\Eitan\.m2\repository\org\apache\commons\commons-lang3\3.3.2\commons-lang3-3.3.2.jar

【问题讨论】:

  • 请提供您的错误内联代码(4 个缩进)作为开始。轻松复制/粘贴,快速浏览。让我们也不要对您需要的所有库进行逆向工程,让我们从一个健康(尽力而为)的 pom.xml 开始。您使用哪个依赖项来包含“Elasticsearch”?提供另一个与依赖项内联的代码片段。
  • 请将 -verbose:class 添加到执行并发布结果。它会准确地告诉你正在加载哪些 jars 以及从哪里加载
  • 感谢@ChristianBongiorno 和JoD。不确定如何使用 --verbose 但我确实运行了 System.out.println(System.getProperty("java.class.path")) 来列出所有加载的类。我可以看到 appache-common-lang 被写了两次(相同的版本)...
  • 另外,我的印象是问题出在 Maven-Eclipse 的某个地方,所以我手动将所有相关的 JAR 加载到构建路径中并禁用了 Maven
  • 在详细中找到这两个条目:第 9 行:C:\Users\Eitan\workspace\SelfAnomalyDetector - ver7\JARs For Jest\commons-lang3-3.3.2.jar;第 64 行:C:\Users\Eitan\.m2\repository\org\apache\commons\commons-lang3\3.3.2\commons-lang3-3.3.2.jar

标签: java eclipse classpath buildpath elasticsearch-jest


【解决方案1】:

只是浏览,甚至不知道您要做什么,我的第一个猜测是这两个主要依赖项应该足够了:

<dependency>
  <groupId>io.searchbox</groupId>
  <artifactId>jest</artifactId>
  <version>0.1.1</version>
</dependency>
<dependency>
  <groupId>org.elasticsearch</groupId>
  <artifactId>elasticsearch</artifactId>
  <version>1.0.1</version>
</dependency>

我的猜测是您混合了两个版本的appache-common-lang3。一个可能会被重新包装为另一个的一部分。

但是,我检查了您的所有依赖项(我可以在您的快照中看到),但找不到 apache-common-lang3 的重新打包:

  • 开玩笑
  • jest-common - 它确实有嵌套的依赖来自动拉入 apache-common-lang3
  • gson
  • 弹性搜索

我还检查了刚才提到的所有嵌套依赖项。没有重新包装的痕迹。所以现在不确定。

我希望你也没有自定义你的类路径,或者在你的 java 安装的 lib/ext 的某个地方手动放置一个库版本。

【讨论】:

  • 嗨,我从 Maven 中分离了这个项目,所以现在有 POM 与依赖项。我手动将所有 JARS 放入项目中。另外,我没有手动自定义类路径,但是当我使用时: System.out.println(System.getProperty("java.class.path")) 我看到 appache-common-lang 3 从 2 加载了两次不同的位置。 (相同版本)这有关系吗?
  • *没有 POM(而不是现在的 POM...)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-20
  • 2013-12-07
  • 1970-01-01
  • 1970-01-01
  • 2020-10-29
  • 2018-04-04
  • 2019-04-23
相关资源
最近更新 更多