Elasticsearch Java API from web application-error: java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.threadpool.ThreadPool


(do) #1

I have learned about elasticsearch. I have a problem as follow:
I have installed elasticseach 2.4.1 on my project with maven:

<dependency>
      <groupId>org.elasticsearch</groupId>
      <artifactId>elasticsearch</artifactId>
      <version>2.4.1</version>
<dependency>
         <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
         <version>18.0</version>
</dependency>

I create a class and using NodeClient

Node node = NodeBuilder.nodeBuilder().settings(Settings.builder()
.put("path.home", "/path/to/elasticsearch/home/dir")).node();
org.elasticsearch.client.Client client = node.client();

Always after building the project at the first load the below error will appear:

java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;

and after change guava library to version 19.0 or 20.0 then error appear:

java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.threadpool.ThreadPool

I really appreciate you for sharing your knowledge.


(Daniel Mitterdorfer) #2

Hi @doln,

it seems to me that you need to shade the elasticsearch jar and all conflicting dependencies.

Note: In Elasticsearch 5, we've created a new REST client library which spares you that hassle. The REST client library is low-level at the moment but we work on a high-level client.

Daniel


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.