# ExceptionInInitializer and NoClassDefFound could not initialize class org.elasticsearch.client.RestClientBuilder

**URL:** <https://discuss.elastic.co/t/exceptionininitializer-and-noclassdeffound-could-not-initialize-class-org-elasticsearch-client-restclientbuilder/369813>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [October 30, 2024, 12:51pm UTC](https://discuss.elastic.co/t/exceptionininitializer-and-noclassdeffound-could-not-initialize-class-org-elasticsearch-client-restclientbuilder/369813 "2024-10-30T12:51:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Radha\_G](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radha_g/32/137577_2.png) [@Radha\_G](https://discuss.elastic.co/u/Radha_G)\
**Post date:** [October 30, 2024, 12:51pm UTC](https://discuss.elastic.co/t/exceptionininitializer-and-noclassdeffound-could-not-initialize-class-org-elasticsearch-client-restclientbuilder/369813/1 "2024-10-30T12:51:33Z")

</div>

Hi All,

I have replaced org.elasticsearch.client.RestHighLevelClient to co.elastic.clients.elasticsearch.ElasticsearchClient . But, when mvn clean verify command is executed, the following exception is being thrown :

[ERROR] Failures:  
[ERROR]AbstractTestNGSpringContextTests.run:154-\>testHighLevelClient» ExceptionInInitializer  
[ERROR] RepositoryTest.destroy:393 » NoClassDefFound Could not initialize clas s org.elasticsearch.client.RestClientBuilder  
[ERROR] RepositoryTest.init:66-\>createIndex:359 » NoClassDefFound Could not in itialize class org.elasticsearch.client.RestClientBuilder

Below dependencies have been added to the pom.xml:

 co.elastic.clients elasticsearch-java 7.17.20 org.elasticsearch.client elasticsearch-rest-client 7.17.20 org.elasticsearch elasticsearch 7.17.20 

Below method is throwing the exception

import co.elastic.clients.elasticsearch.ElasticsearchClient;  
import co.elastic.clients.json.jackson.JacksonJsonpMapper;  
import co.elastic.clients.transport.rest\_client.RestClientTransport;

public ElasticsearchClient newEs7HighLevelClient() {  
org.elasticsearch.client.RestClient restClient= org.elasticsearch.client .RestClient.builder(new HttpHost("localhost",9200,"http")).build();  
RestClientTransport transport= new RestClientTransport(restClient,new Ja cksonJsonpMapper()) ;  
ElasticsearchClient esClient= new ElasticsearchClient(transport);  
return esClient;  
}

Could anyone suggest some solution to resolve this issue.

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [October 30, 2024, 2:57pm UTC](https://discuss.elastic.co/t/exceptionininitializer-and-noclassdeffound-could-not-initialize-class-org-elasticsearch-client-restclientbuilder/369813/2 "2024-10-30T14:57:55Z")

</div>

Hello and welcome.

The `elasticsearch-java` dependency already includes `elasticsearch-rest-client`, so there's no need to import it, also no need to import `elasticsearch`.

---

<div class="post-metadata">

**Author:** ![Radha\_G](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radha_g/32/137577_2.png) [@Radha\_G](https://discuss.elastic.co/u/Radha_G)\
**Post date:** [October 30, 2024, 6:13pm UTC](https://discuss.elastic.co/t/exceptionininitializer-and-noclassdeffound-could-not-initialize-class-org-elasticsearch-client-restclientbuilder/369813/3 "2024-10-30T18:13:51Z")

</div>

Hi Laura,

Thanks for the inputs. Is that the root cause for this issue. I will remove those imports.

---

<div class="post-metadata">

**Author:** ![Radha\_G](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radha_g/32/137577_2.png) [@Radha\_G](https://discuss.elastic.co/u/Radha_G)\
**Post date:** [October 30, 2024, 6:17pm UTC](https://discuss.elastic.co/t/exceptionininitializer-and-noclassdeffound-could-not-initialize-class-org-elasticsearch-client-restclientbuilder/369813/4 "2024-10-30T18:17:25Z")

</div>

import co.elastic.clients.elasticsearch.ElasticsearchClient;  
import co.elastic.clients.json.jackson.JacksonJsonpMapper;  
import co.elastic.clients.transport.rest\_client.RestClientTransport;

public ElasticsearchClient newHighLevelClient() {  
org.elasticsearch.client.RestClient restClient= org.elasticsearch.client .RestClient.builder(new HttpHost("localhost",9200,"http")).build();  
RestClientTransport transport= new RestClientTransport(restClient,new Ja cksonJsonpMapper()) ;  
ElasticsearchClient esClient= new ElasticsearchClient(transport);  
return esClient;  
}

The above method is throwing exceptioninInitializer.

---

<div class="post-metadata">

**Author:** ![ltrotta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ltrotta/32/124003_2.png) [@ltrotta](https://discuss.elastic.co/u/ltrotta)\
**Post date:** [October 30, 2024, 6:39pm UTC](https://discuss.elastic.co/t/exceptionininitializer-and-noclassdeffound-could-not-initialize-class-org-elasticsearch-client-restclientbuilder/369813/5 "2024-10-30T18:39:25Z")

</div>

Now that the import issue has been solved you can refer to the [migration guide](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/migrate-hlrc.html) and to the [getting started guide](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/getting-started-java.html) to learn how to use the new client.

We also have a [blog post](https://www.elastic.co/blog/switching-from-the-java-high-level-rest-client-to-the-new-java-api-client) that explains the migration process in details.
