Issue with elastic search 5.0.0 - NoClassDefFoundError: org/apache/logging/log4j/Logger

Hi,

i am in the process of converting the elastic search version from 2.x to 5.0.0.
i am seeing the below error when i try to initialize the client.
client = new PreBuiltTransportClient(settings);

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/logging/log4j/Logger
at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:105)
at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:72)
at org.elasticsearch.common.component.AbstractComponent.(AbstractComponent.java:37)
at org.elasticsearch.plugins.PluginsService.(PluginsService.java:110)
at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:81)
at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:106)
at org.elasticsearch.client.transport.TransportClient.(TransportClient.java:228)
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:69)
at org.elasticsearch.transport.client.PreBuiltTransportClient.(PreBuiltTransportClient.java:65)

am having the below dependencies in pom.xml

                <dependency>
		<groupId>org.elasticsearch</groupId>
		<artifactId>elasticsearch</artifactId>
		<version>5.0.0</version>
	</dependency>
	<dependency>
                <groupId>org.elasticsearch.client</groupId>
                   <artifactId>transport</artifactId>
             <version>5.0.0</version>
         </dependency>

please help.

thanks

You have to add logging dependencies:

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.7</version>
            <scope>test</scope>
        </dependency>
1 Like

https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_java_api_changes.html#_elasticsearch_will_no_longer_detect_logging_implementations

With ES 5 you have to explicitly include Log4J 2 as dependency in your pom.

Managed to get Logging to work with sbt Scala over slf4j with these deps:

  "org.slf4j" % "slf4j-simple" % "1.7.21",
  "org.apache.logging.log4j" % "log4j-api" % "2.6.2",
  "org.apache.logging.log4j" % "log4j-to-slf4j" % "2.6.2",

Note log4j 2.7 does not seem to work with ElasticSearch 5.0.0

1 Like

Yes. I faced the same issue with Log4j 2.7.

I followed your steps and compiled successfully.

Same issue ,i use slf4j, resovled by add

org.apache.logging.log4j
log4j-to-slf4j
2.6.2


org.apache.logging.log4j
log4j-api


org.apache.logging.log4j
log4j-core

please refer https://logging.apache.org/log4j/2.0/log4j-slf4j-impl/index.html

None of the combinations above worked for me. I have tried up to this version of artifacts:

"org.elasticsearch" % "elasticsearch" % "5.2.1", // "1.7.1",
"org.elasticsearch.client" % "transport" % "5.2.1", // "1.7.1",
//"org.apache.logging.log4j" % "log4j-to-slf4j" % "2.8",
"org.slf4j" % "slf4j-simple" % "1.7.24",
"org.apache.logging.log4j" % "log4j-api" % "2.8.1",
"org.apache.logging.log4j" % "log4j-core" % "2.8.1",

Any suggestions?

For the win:

"org.elasticsearch" % "elasticsearch" % "5.2.1", // "1.7.1",
//"org.elasticsearch.client" % "transport" % "5.2.1", // "1.7.1",
"org.apache.logging.log4j" % "log4j-to-slf4j" % "2.8",
//"org.slf4j" % "slf4j-simple" % "1.7.24",
"org.apache.logging.log4j" % "log4j-api" % "2.8.1",
"org.apache.logging.log4j" % "log4j-core" % "2.8.1",

The maven dependencies in this thread helped: