Unhandled java.lang.NoClassDefFoundError in Elasticsearch High-Level RestClientBuilder

Hi All,

I get the following error when running "sbt test" (scalatest with matchers) that helps with unit testing a method written in scala. The method creates an instance of Elasticsearch REST High-Level client followed by a SearchRequest query to the ES cluster. When I execute the unit test, I see the following error. To troubleshoot I did check for the jars in my classpath (sbt > show test:full-classpath) and have the following jars available. Yet the ES connection to the cluster cannot be established to execute the search query.

  • httpasyncclient-4.1.2.jar

  • httpclient-4.5.3.jar

  • httpcore-nio-4.4.5.jar

  • Elasticsearch version: 6.2.3 (elasticsearch-rest-high-level-client-6.2.3.jar)

Unhandled java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionFactory

java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.nio.conn.ManagedNHttpClientConnectionFactory
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingNHttpClientConnectionManager.java:553)
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.<init>(PoolingNHttpClientConnectionManager.java:163)
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.<init>(PoolingNHttpClientConnectionManager.java:147)
	at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.<init>(PoolingNHttpClientConnectionManager.java:119)
	at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(HttpAsyncClientBuilder.java:668)
	at org.elasticsearch.client.RestClientBuilder$2.run(RestClientBuilder.java:218)
	at org.elasticsearch.client.RestClientBuilder$2.run(RestClientBuilder.java:215)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.elasticsearch.client.RestClientBuilder.createHttpClient(RestClientBuilder.java:215)
	at org.elasticsearch.client.RestClientBuilder.access$000(RestClientBuilder.java:42)
	at org.elasticsearch.client.RestClientBuilder$1.run(RestClientBuilder.java:187)
	at org.elasticsearch.client.RestClientBuilder$1.run(RestClientBuilder.java:184)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.elasticsearch.client.RestClientBuilder.build(RestClientBuilder.java:184)
	at org.elasticsearch.client.RestHighLevelClient.<init>(RestHighLevelClient.java:200)
	at org.elasticsearch.client.RestHighLevelClient.<init>(RestHighLevelClient.java:192)
        at xxxxxx.RestManager.<init>(RestManager.scala:28)

My rest high-level client scala code looks like the following:

  class RestManager extends Serializable {
    	val builder =  RestClient.builder(
          new HttpHost("node1", 9200, "http"))
      builder.setRequestConfigCallback(new RequestConfigCallback() {
        override def customizeRequestConfig(requestConfigBuilder: RequestConfig.Builder) : RequestConfig.Builder =
        {
          requestConfigBuilder.setConnectTimeout(10000).setSocketTimeout(60000)
         }
   })
   .setMaxRetryTimeoutMillis(60000)
   val client: RestHighLevelClient  = new RestHighLevelClient(builder)
   }

   object restClient extends RestManager

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