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


(Kumar1993) #1

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.


(David Pilato) #2

You just need to add:

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

Nothing else.


(Kumar1993) #3

I have added that already.


(Kumar1993) #4

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


(David Pilato) #5

I believe this

compile 'log4j:log4j:1.2.16'

Is clashing with logger needed by the client.


(David Pilato) #6

Also this:

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

Is weird.


(Kumar1993) #7

I removed both of them, but still no luck.


(David Pilato) #8

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

I'd:

  • Start a sample project with only:
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.


(Corey Quon) #9

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.


(system) #10

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