java.lang.ClassNotFoundException: org.apache.log4j.Logger with elasticsearch and neo4j

568 views Asked by At

I am writing a neo4j plugin in which I want to use elasticsearch. While running the neo4j, I am getting the following error:

ERROR Failed to start Neo4j: Starting Neo4j failed: Component 'org.neo4j.server.database.LifecycleManagingDatabase@435a13ac' was successfully initialized, but failed to start. Please see the attached cause exception "org.apache.log4j.Logger". Starting Neo4j failed: Component 'org.neo4j.server.database.LifecycleManagingDatabase@435a13ac' was successfully initialized, but failed to start. Please see the attached cause exception "org.apache.log4j.Logger".
org.neo4j.server.ServerStartupException: Starting Neo4j failed: Component 'org.neo4j.server.database.LifecycleManagingDatabase@435a13ac' was successfully initialized, but failed to start. Please see the attached cause exception "org.apache.log4j.Logger".
    at org.neo4j.server.exception.ServerStartupErrors.translateToServerStartupError(ServerStartupErrors.java:68)
    at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:219)
    at org.neo4j.server.ServerBootstrapper.start(ServerBootstrapper.java:111)
    at org.neo4j.server.ServerBootstrapper.start(ServerBootstrapper.java:79)
    at org.neo4j.server.CommunityEntryPoint.main(CommunityEntryPoint.java:32)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.server.database.LifecycleManagingDatabase@435a13ac' was successfully initialized, but failed to start. Please see the attached cause exception "org.apache.log4j.Logger".
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:466)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
    at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:211)
    ... 3 more
Caused by: java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory, /home/gaurav_verma/.ineo/instances/staging2/data/databases/graph.db
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:211)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:126)
    at org.neo4j.server.CommunityNeoServer.lambda$static$0(CommunityNeoServer.java:58)
    at org.neo4j.server.database.LifecycleManagingDatabase.start(LifecycleManagingDatabase.java:88)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:445)
    ... 5 more
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.proc.Procedures@72c8de78' was successfully initialized, but failed to start. Please see the attached cause exception "org.apache.log4j.Logger".
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:466)
    at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
    at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.initFacade(GraphDatabaseFacadeFactory.java:207)
    ... 9 more
Caused by: java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
    at java.lang.Class.getDeclaredFields(Class.java:1916)
    at org.neo4j.kernel.impl.proc.FieldInjections.setters(FieldInjections.java:90)
    at org.neo4j.kernel.impl.proc.ReflectiveProcedureCompiler.compileFunction(ReflectiveProcedureCompiler.java:318)
    at org.neo4j.kernel.impl.proc.ReflectiveProcedureCompiler.compileFunction(ReflectiveProcedureCompiler.java:119)
    at org.neo4j.kernel.impl.proc.ProcedureJarLoader.loadProcedures(ProcedureJarLoader.java:95)
    at org.neo4j.kernel.impl.proc.ProcedureJarLoader.loadProceduresFromDir(ProcedureJarLoader.java:82)
    at org.neo4j.kernel.impl.proc.Procedures.start(Procedures.java:275)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:445)
    ... 11 more
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 21 more

Following is my pom entries:

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

<dependency>
     <groupId>log4j</groupId>
     <artifactId>log4j</artifactId>
     <version>1.2.17</version>
</dependency>

I have tried using the log4j-core and log4j-api pom entries also, but still getting the same error. I also saw the dependency tree and found two conflicting versions of commons-logging:commons-logging:jar , but I don't know how to solve this.

Can anyone tell me what is the issue and how to solve this.

1

There are 1 answers

1
gjoranv On

Please try with this dependency:

<dependency>
     <groupId>org.slf4j</groupId>
     <artifactId>log4j-over-slf4j</artifactId>
     <version>1.7.25</version>
</dependency>

Often, you can resolve such exceptions by searching for the full class name on search.maven.org.