2017-05-25 56 views
0

我正在使用java elasticsearch 5.4 api。當我運行示例程序我得到以下錯誤Elasticsearch java api錯誤java.lang.NoClassDefFoundError:org/apache/logging/log4j/Logger

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger 
    at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:101) 
    at org.elasticsearch.common.xcontent.support.AbstractXContentParser.<init>(AbstractXContentParser.java:57) 
    at org.elasticsearch.common.xcontent.json.JsonXContentParser.<init>(JsonXContentParser.java:44) 
    at org.elasticsearch.common.xcontent.json.JsonXContent.createParser(JsonXContent.java:103) 
    at org.elasticsearch.common.settings.Setting.parseableStringToList(Setting.java:848) 
    at org.elasticsearch.common.settings.Setting.lambda$listSetting$27(Setting.java:802) 
    at org.elasticsearch.common.settings.Setting.listSetting(Setting.java:807) 
    at org.elasticsearch.common.settings.Setting.listSetting(Setting.java:802) 
    at org.elasticsearch.common.network.NetworkService.<clinit>(NetworkService.java:50) 
    at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:98) 
    at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:126) 
    at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:268) 
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:125) 
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:111) 
    at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:101) 
    at com.ibm.esclient.ESClient.main(ESClient.java:33) 
Caused by: java.lang.ClassNotFoundException: org.apache.logging.log4j.Logger 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 

我的依賴是

<dependencies> 
     <dependency> 
      <groupId>org.elasticsearch.client</groupId> 
      <artifactId>transport</artifactId> 
      <version>5.4.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-api</artifactId> 
      <version>2.8</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-core</artifactId> 
      <version>2.8 
      </version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-slf4j-impl</artifactId> 
      <version>2.8</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-web</artifactId> 
      <version>2.8</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.logging.log4j</groupId> 
      <artifactId>log4j-to-slf4j</artifactId> 
      <version>2.8</version> 
     </dependency> 
     <dependency> 
    <groupId>ch.qos.logback</groupId> 
    <artifactId>logback-classic</artifactId> 
    <version>1.1.7</version> 
</dependency> 
    </dependencies> 

基本上我試圖在這裏,但無濟於事添加所有可能的log4j記錄器。非常沮喪,需要幫助!

+0

其中一些依賴關係已過時。例如logback-classic是1.2.3版本。 –

+0

我試過你的建議。還是一樣! – Shades88

回答

2

一個小錯誤導致了這個錯誤。我已經指定爲測試。我刪除它,並開始工作

0

以防萬一 - 如果日誌配置正確,問題只發生在添加ES依賴不會更容易解決方案只是添加排除ES log4j依賴(而不是增加更多的記錄器)?

在gradle這個是這樣的:

compile ('org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.2'){ 
    exclude group: 'org.apache.logging.log4j' 
} 

解決了NoClassDefFoundError的例外就好了。