# Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ReflectionUtil

**URL:** <https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651>\
**Category:** Elasticsearch\
**Created:** [October 4, 2017, 6:34am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651 "2017-10-04T06:34:42Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumar1993](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@kumar1993](https://discuss.elastic.co/u/kumar1993)\
**Post date:** [October 4, 2017, 6:34am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/1 "2017-10-04T06:34:42Z")

</div>

Hi I have followed the tutorial on the elastic search website and i am instantiating a High level rest client in java, but when i try to do this i run into the following exception: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/util/ReflectionUtil  
I have included log4j-api and log4j-core and related dependencies in my build.gradle file, not able to get why i am facing this error.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 4, 2017, 7:05am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/2 "2017-10-04T07:05:32Z")

</div>

You just need to add:

```auto
dependencies {
    compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:5.6.2'
}

```

Nothing else.

---

<div class="post-metadata">

**Author:** ![kumar1993](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@kumar1993](https://discuss.elastic.co/u/kumar1993)\
**Post date:** [October 4, 2017, 7:44am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/3 "2017-10-04T07:44:23Z")

</div>

I have added that already.

---

<div class="post-metadata">

**Author:** ![kumar1993](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@kumar1993](https://discuss.elastic.co/u/kumar1993)\
**Post date:** [October 4, 2017, 7:45am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/4 "2017-10-04T07:45:40Z")

</div>

compile 'log4j:log4j:1.2.16'  
compile 'com.microsoft:sqljdbc4:4.0.2206.100'  
compile 'org.eclipse.jetty:jetty-server:8.1.16.v20140903'  
compile 'org.elasticsearch.client:transport:5.2.0'  
compile 'org.eclipse.persistence:eclipselink:2.5.2'  
compile 'com.google.code.gson:gson:2.3.1'  
compile 'com.opencsv:opencsv:3.8'  
compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.1.0.jre8'  
testCompile 'junit:junit:4.10'  
// compile 'com.oracle:ojdbc7:1.0'  
compile 'com.googlecode.json-simple:json-simple:1.1.1'  
compile group: 'org.apache.commons', name: 'commons-configuration2', version: '2.0'  
compile group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.1.3'  
compile group: 'org.apache.httpcomponents', name: 'httpcore-nio', version: '4.4.7'  
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'  
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.7'  
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'  
compile group: 'commons-logging', name: 'commons-logging', version: '1.2'

```
//compile 'org.slf4j:log4j-over-slf4j:1.7.0'
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'org.slf4j:slf4j-log4j12:1.7.21'
compile 'com.floragunn:search-guard-5:5.4.0-12'
compile 'com.floragunn:search-guard-ssl:5.4.0-12'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2'
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.6'
compile group:'org.apache.commons',name:'commons-dbcp2',version:'2.0.1'

compile 'com.fasterxml.jackson.core:jackson-databind:2.8.6'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-to-slf4j
compile group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: '2.7'
// https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-core-asl
compile group: 'org.codehaus.jackson', name: 'jackson-core-asl', version: '1.9.13'
compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:5.6.2'
// https://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl
compile group: 'org.codehaus.jackson', name: 'jackson-mapper-asl', version: '1.9.13'
testCompile "org.mockito:mockito-core:1.+"
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.6.5'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.6.5'

```

this is the contents of the dependencies section

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 4, 2017, 7:57am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/5 "2017-10-04T07:57:28Z")

</div>

I believe this

```auto
compile 'log4j:log4j:1.2.16'

```

Is clashing with logger needed by the client.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 4, 2017, 7:58am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/6 "2017-10-04T07:58:41Z")

</div>

Also this:

```auto
compile 'org.elasticsearch.client:transport:5.2.0'

```

Is weird.

---

<div class="post-metadata">

**Author:** ![kumar1993](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@kumar1993](https://discuss.elastic.co/u/kumar1993)\
**Post date:** [October 4, 2017, 8:21am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/7 "2017-10-04T08:21:35Z")

</div>

I removed both of them, but still no luck.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 4, 2017, 8:38am UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/8 "2017-10-04T08:38:19Z")

</div>

Yes. You have tons of dependencies here which might conflict with elasticsearch deps.

I'd:

- Start a sample project with only:

```auto
dependencies {
    compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:5.6.2'
}

```

- Add the only needed ones for your project, one by one
- Find if any which one is clashing.

For sure you need to clean your dependencies.

---

<div class="post-metadata">

**Author:** ![cquon](https://avatars.discourse-cdn.com/v4/letter/c/cdc98d/32.png) [@cquon](https://discuss.elastic.co/u/cquon)\
**Post date:** [October 13, 2017, 7:06pm UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/9 "2017-10-13T19:06:46Z")

</div>

I have faced a similar issue.

Can you try:

compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.8.2'  
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.2'

Changing those versions to 2.9.1?

Appeared to resolve it for me.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 10, 2017, 7:06pm UTC](https://discuss.elastic.co/t/exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-logging-log4j-util-reflectionutil/102651/10 "2017-11-10T19:06:58Z")

</div>

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