log4j and log4j-overslf4j both in classpath conflicts in LogManager - java

we are using log4j-over-slf4j for logging in our application. But one of jar dependency in our application(External to us) needs log4j specific class(org.apache.log4j.spi.RepositorySelector). So, I have added log4j also in our classpath and It was able to find that class,
But, then I start to face new issue, In my code, I am loading RepositorySelectorfrom LogManager,
LogManager.setRepositorySelector(repoSel, guard);
Now, instead of referring to log4j specific LogManager, It is referring to log4j-over-slf4j specific LogManager, due to which , I am getting below error in websphere server console.
Caused by: java.lang.NoSuchMethodError: org/apache/log4j/LogManager.setRepositorySelector(Lorg/apache/log4j/spi/RepositorySelector;Ljava/lang/Object;)V**
Please help me know, how can we remove the conflict, so that, It's able to refer proper log4j1.2.15 specific LogManager.
And, as jar which is using log4j is external to our system, we don't have much control over that.
Below is the complete stack trace.
Caused by: java.lang.NoSuchMethodError: org/apache/log4j/LogManager.setRepositorySelector(Lorg/apache/log4j/spi/RepositorySelector;Ljava/lang/Object;)V
at com.hsbc.es.logging.def.impl.log4j.Log4jLoggingTypeProvider.setContextualRepositorySelector(Log4jLoggingTypeProvider.java:117)
at com.hsbc.es.logging.def.impl.log4j.Log4jLoggingTypeProvider.<clinit>(Log4jLoggingTypeProvider.java:97)
at java.lang.J9VMInternals.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1887)
at com.hsbc.es.logging.LoggingTypeManagerFactory.discoverContextLoggingTypeManagerSPI(LoggingTypeManagerFactory.java:168)
at com.hsbc.es.logging.LoggingTypeManagerFactory.getContextLoggingTypeManagerSPI(LoggingTypeManagerFactory.java:98)
at com.hsbc.es.logging.def.LoggingTypeProviderFactory.getContextLoggingTypeProvider(LoggingTypeProviderFactory.java:49)
at com.hsbc.es.logging.def.LoggingTypeFactory.getDebugger(LoggingTypeFactory.java:58)

You can exclude the transitive log4j dependency from being imported by the dependency that includes it.
In your pom.xml you can tell update your dependency import in order to exclude log4j:
<dependencies>
<dependency>
<groupId>the.group.id</groupId>
<actifactId>the.artifact.id</artifactId>
<version>version-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Related

Difference between slf4j-log4j12 vs log4j

In a project's pom.xml I am seeing a dependency like below
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
Can someone let me know what is the difference between slf4j-log4j12 & log4j ?
Log4j 1.2
slf4j-log4j12 provides a bridge between SLF4J and Log4j 1.2 so that SLF4J knows about how to log using Log4j.
You are using Log4j 1.2. That version's binding it is maintained by the SLF4J project. Here is a summary from the SLF4J docs:
SLF4J supports various logging frameworks. The SLF4J distribution ships with several jar files referred to as "SLF4J bindings", with each binding corresponding to a supported framework.
slf4j-log4j12-1.7.28.jar
Binding for log4j version 1.2, a widely used logging framework. You also need to place log4j.jar on your class path.
Log4j 2
If you are using Log4j 2 or later, you will need a different binding JAR than slf4j-log4j12. That binding is maintained by the Log4j project. According to the Log4j docs:
The Log4j 2 SLF4J Binding allows applications coded to the SLF4J API to use Log4j 2 as the implementation.
You must provide both dependencies if you want SLF4J to route logging to Log4j. Again, from the Log4j 2 docs:
Simply include the Log4j 2 SLF4J Binding jar along with the Log4j 2 jars and SLF4J API jar to cause all SLF4J logging to be handled by Log4j 2.
To summarize:
<dependency> <!--Facade for logging systems-->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency> <!--Log4j 2 implementation for slf4j-->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.12.0</version>
</dependency>
In addition make sure that you are using a log4j2 properties file. The mistake of using 'log4j.xml' did cost me quite some time
I'll post some points regarding these logger message.
log4j:
logger.debug("This is log message:" + msg);
log4j string is concatenated every time the line is evaluated even if log level is lower than debug so the string will never be used.
slf4j:
logger.debug("this is log slf4j message",msg);
slf4j string and parameters are passed through to the logger which only substitutes them if the log message is actually to be used.
The only difference is the performance. Where log4j will take more time because of string concatenation compare to slf4j.
Slf4j:
An abstract layer for the logging component.
We can change logging at point of time without much changes in code.
Log4j:
A logging component which provides core functionalities of logging.

Storm Topology not submit

i have configured my machine zookeeper,nimbus,supervisor are running properly and my topology working in LocalCluster
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("SendPost", conf, builder.createTopology());
Utils.sleep(10000000000l);
cluster.killTopology("SendPost");
cluster.shutdown();
now i want try submit my topology bt it not working
/usr/local/storm/bin$ ./storm jar /home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.winoria.post.PostTopology Post
i getting following error
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/storm/lib/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Running: java -client -Dstorm.options= -Dstorm.home=/usr/local/storm -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dstorm.conf.file= -cp /usr/local /storm/storm-netty-0.9.0.1.jar:/usr/local/storm/storm-console-logging-0.9.0.1.jar:/usr/local/storm/storm-core-0.9.0.1.jar:/usr/local/storm/lib/httpcore-4.1.jar:/usr/local/storm/lib/carbonite-1.5.0.jar:/usr/local/storm/lib/mockito-all-1.9.5.jar:/usr/local/storm/lib/commons-io-1.4.jar:/usr/local/storm/lib/commons-fileupload-1.2.1.jar:/usr/local/storm/lib/jgrapht-0.8.3.jar:/usr/local/storm/lib/ring-jetty-adapter-0.3.11.jar:/usr/local/storm/lib/jzmq-2.1.0.jar:/usr/local/storm/lib/asm-4.0.jar:/usr/local/storm/lib/logback-core-1.0.6.jar:/usr/local/storm/lib/tools.nrepl-0.2.3.jar:/usr/local/storm/lib/compojure-1.1.3.jar:/usr/local/storm/lib/json-simple-1.1.jar:/usr/local/storm/lib/ring-devel-0.3.11.jar:/usr/local/storm/lib/commons-logging-1.1.1.jar:/usr/local/storm/lib/httpclient-4.1.1.jar:/usr/local/storm/lib/reflectasm-1.07-shaded.jar:/usr/local/storm/lib/commons-exec-1.1.jar:/usr/local/storm/lib/guava-13.0.jar:/usr/local/storm/lib/clout-1.0.1.jar:/usr/local/storm/lib/objenesis-1.2.jar:/usr/local/storm/lib/slf4j-api-1.6.5.jar:/usr/local/storm/lib/clojure-1.4.0.jar:/usr/local/storm/lib/jetty-6.1.26.jar:/usr/local/storm/lib/hiccup-0.3.6.jar:/usr/local/storm/lib/clj-stacktrace-0.2.2.jar:/usr/local/storm/lib/log4j-over-slf4j-1.6.6.jar:/usr/local/storm/lib/tools.logging-0.2.3.jar:/usr/local/storm/lib/ring-core-1.1.5.jar:/usr/local/storm/lib/zookeeper-3.3.3.jar:/usr/local/storm/lib/math.numeric-tower-0.0.1.jar:/usr/local/storm/lib/disruptor-2.10.1.jar:/usr/local/storm/lib/minlog-1.2.jar:/usr/local/storm/lib/core.incubator-0.1.0.jar:/usr/local/storm/lib/servlet-api-2.5-20081211.jar:/usr/local/storm/lib/netty-3.6.3.Final.jar:/usr/local/storm/lib/ring-servlet-0.3.11.jar:/usr/local/storm/lib/clj-time-0.4.1.jar:/usr/local/storm/lib/snakeyaml-1.11.jar:/usr/local/storm/lib/commons-codec-1.4.jar:/usr/local/storm/lib/tools.cli-0.2.2.jar:/usr/local/storm/lib/logback-classic-1.0.6.jar:/usr/local/storm/lib/servlet-api-2.5.jar:/usr/local/storm/lib/kryo-2.17.jar:/usr/local/storm/lib/joda-time-2.0.jar:/usr/local/storm/lib/curator-client-1.0.1.jar:/usr/local/storm/lib/libthrift7-0.7.0-2.jar:/usr/local/storm/lib/tools.macro-0.1.0.jar:/usr/local/storm/lib/jline-0.9.94.jar:/usr/local/storm/lib/clojure-complete-0.2.3.jar:/usr/local/storm/lib/curator-framework-1.0.1.jar:/usr/local/storm/lib/commons-lang-2.5.jar:/usr/local/storm/lib/junit-3.8.1.jar:/usr/local/storm/lib/jetty-util-6.1.26.jar:/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar:/usr/local/storm/conf:/usr/local/storm/bin -Dstorm.jar=/home/winoria/Desktop/Storm/storm-starter/target/storm-starter-0.0.1-SNAPSHOT-jar-with-dependencies.jar com.winoria.post.PostTopology Post
SLF4J: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError.
SLF4J: See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.apache.log4j.Logger.getLogger(Logger.java:39)
at org.apache.log4j.Logger.getLogger(Logger.java:43)
at com.rapportive.storm.spout.AMQPSpout.<clinit>(AMQPSpout.java:67)
at com.winoria.post.PostTopology.main(PostTopology.java:33)
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND slf4j- log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
at org.apache.log4j.Log4jLoggerFactory.<clinit>(Log4jLoggerFactory.java:49)
... 4 more
plz help me ...........
thanks in advance
I used cassandra and cassandra-all version 1.6.1 declares both log4j and slf4j-log4j12 as compile-time dependencies so I add following dependencies and my topology work like charm !!!
<dependencies>
<dependency>
<groupId> org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>1.1.6</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Try to exclude either log4j-over-slf4j.jar or slf4j-log4j12.jar from your classpath. I don't know which build tool do you use. Check the documentation of your build tool to see how to exclude a dependency.
For more reference: Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar on the class path, preempting StackOverflowError
You have to exclude all occurrences of slf4j-log4j12.jar . . . It doesn't work if you exclude all occurrences of log4j-over-slf4j.jar because Apache Storm adds log4j-over-slf4j at runtime (through the storm-core dependency in your pom.xml). Even when I added exclude log4j-over-slf4j to the storm-core dependency it would still be brought back at runtime.
If after exclude either log4j-over-slf4j.jar or slf4j-log4j12.jar , you still got this error. See in your jar, if both these two classes exist: org.slf4j.impl.log4jloggerfactory and org.apache.log4j.log4jloggerfactory .
And then find if any other jars besides slf4j and log4j contains these two classes.
In my situation, there is org.slf4j.impl.log4jloggerfactory in activemq. The error log really mislead me for a long time.

no such method jsch.JSch.setLogger

The below behavior occurs when i call the getSftpUtil(). I have also ensured that all the appropriate jars are in the maven project's external libraries and are available in the WEB-INF/lib folder of the project
code
net.sf.opensftp.SftpUtil util = SftpUtilFactory.getSftpUtil();
stacktrace
SftpUtilFactory: Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory - Trying to get SftpUtil class name from the system property net.sf.opensftp.SftpUtil
SftpUtilFactory: The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory - The system property net.sf.opensftp.SftpUtil is not set.
SftpUtilFactory: Use the default one.
SftpUtilFactory - Use the default one.
Caused by: java.lang.NoSuchMethodError: com.jcraft.jsch.JSch.setLogger(Lcom/jcraft/jsch/Logger;)V
at net.sf.opensftp.impl.SftpUtil.<clinit>(SftpUtil.java:110)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at net.sf.opensftp.SftpUtilFactory.getSftpUtil(SftpUtilFactory.java:184)
Based on jcraft's change log, setLogger is a method added to JSch.java in jsch-0.1.30. So the jar under your WEB-INF/lib should be an older version.
You can run
mvn dependency:tree
to see which of your dependencies is using the older version, and then exclude it with something like this:
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<exclusions>
<exclusion>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
</exclusion>
</exclusions>
</dependency>
You probably have another dependency refer to a more recent version of jsch, so your problem should be solved at this point. However, if that's not the case, you can add this to pom.xml:
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.50</version>
</dependency>
Well, I guess you are missing this dependency or the proper version:
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.49</version> <!--latest version -->

java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory

I am getting the error as mentioned below, while running the feed utility. I am trying to load an image "logo.png". The slf4j jar file is also available in the runtime classpath. But still I am getting this error.
Oct 16, 2012 7:34:11 PM com.ibm.commerce.foundation.dataload.FeedRetriever invokeDataLoad
SEVERE: An error occurred while performing data load.
Throwable occurred: com.ibm.commerce.foundation.dataload.exception.DataLoadException:
An error occurred while executing the data load.
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at com.ibm.commerce.foundation.dataload.DataLoaderMain.execute(DataLoaderMain.java:664)
at com.ibm.commerce.content.commands.DataLoadInvoker.execute(DataLoadInvoker.java:101)
at com.ibm.commerce.foundation.dataload.FeedRetriever.invokeDataLoad(FeedRetriever.java:244)
at com.ibm.commerce.foundation.dataload.FeedRetriever.execute(FeedRetriever.java:172)
at com.ibm.commerce.foundation.dataload.FeedRetriever.main(FeedRetriever.java:321)
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at com.ibm.commerce.foundation.dataload.DataLoaderMain.execute(DataLoaderMain.java:488)
... 4 more
Caused by: java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at org.apache.wink.client.ClientConfig.<clinit>(ClientConfig.java:52)
at java.lang.J9VMInternals.initializeImpl(Native Method)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:167)
at com.ibm.commerce.foundation.dataload.feedreader.AtomReader.getFeed(AtomReader.java:104)
at com.ibm.commerce.foundation.dataload.feedreader.AtomReader.getEntries(AtomReader.java:147)
at com.ibm.commerce.foundation.dataload.feedreader.AtomReader.getEntries(AtomReader.java:1)
at com.ibm.commerce.foundation.dataload.feedreader.BaseFeedReader.init(BaseFeedReader.java:252)
at com.ibm.commerce.foundation.dataload.AbstractBusinessObjectLoader.initializeDataReaders(AbstractBusinessObjectLoader.java:1344)
at com.ibm.commerce.foundation.dataload.AbstractBusinessObjectLoader.init(AbstractBusinessObjectLoader.java:369)
at com.ibm.commerce.foundation.dataload.BusinessObjectLoader.init(BusinessObjectLoader.java:65)
at com.ibm.commerce.foundation.dataload.DataLoaderMain.execute(DataLoaderMain.java:431)
... 4 more
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:76)
at java.net.URLClassLoader.findClass(URLClassLoader.java:396)
at java.lang.ClassLoader.loadClass(ClassLoader.java:660)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
... 16 more
Oct 16, 2012 7:34:11 PM com.ibm.commerce.foundation.dataload.FeedRetriever main
SEVERE: An error occurred while performing data load.
Throwable occurred: com.ibm.commerce.foundation.dataload.exception.DataLoadException: An error has occurred. If this problem persists, contact product support.
at com.ibm.commerce.foundation.dataload.FeedRetriever.invokeDataLoad(FeedRetriever.java:247)
at com.ibm.commerce.foundation.dataload.FeedRetriever.execute(FeedRetriever.java:172)
at com.ibm.commerce.foundation.dataload.FeedRetriever.main(FeedRetriever.java:321)
Add a SLF4J implementation (as you only have its API):
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.26</version>
</dependency>
You have to provide one of the various SLF4J implementation .jar files in the classpath, as well as the interface .jar file. This is documented.
Download slf4j-1.7.5.zip
It holds different jar files.
Go to -> Integration folder after extracting zip and include following jar files
slf4j-api-2.0.99
slf4j-simple-1.6.99
junit-3.8.1
Right click on project properties and follow below steps Project Properties" --> "Deployment Assembly", adding "Java Build Path Entries -> Maven Dependencies
I tried other solutions and the exception didn't go away. So I decompiled the entire jose4j 0.6.5 jar with a Java Decomplier and look at its pom.xml.
I realised it has a specific dependency on slf4j-api, version 1.7.21:
So in my project's pom.xml, I added the exact same dependency, updated my Maven project so that it downloads this jar into my repository and the exception was gone.
However it may bring up another error caused by slf4j itself:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
To overcome this issue, I added the following into my project's pom.xml. So altogether you need to add the following to your pom.xml and my jose4j ran without anymore issues:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
Remember to update your Maven project after amending your pom.xml.
(Right-click Project folder in Eclipse -> Maven -> Update Project..)
I also had the similar problem. I had a maven project and was testing rabbitmq. Firstly it showed me the similar error then I added all the SLF4J dependencies in the maven project and then error changed to "Maven SLF4J: Class path contains multiple SLF4J bindings". Here is the complete list of dependencies from pom.xlm
<dependencies>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
<scope>compile</scope>
</dependency>
</dependencies>
It worked finally.
I was facing a similar issue and below line fixed the issue for me.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
Edit: I realized that I was using spring boot and the version of the dependency was getting pulled from spring-boot-starter-parent.
To be more specific if you are missing the class com.vaadin.external.org.slf4j.LoggerFactory add the below dependency.
<dependency>
<groupId>com.vaadin.external.slf4j</groupId>
<artifactId>vaadin-slf4j-jdk14</artifactId>
<version>1.6.1</version>
</dependency>
If you are missing any other org.slf4j.LoggerFactory, just go to Maven central class name search and search for the exact class name to determine what exact dependency you are missing.
You can use bellow dependency
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.7</version>
</dependency>
Add the following jars to the class path or lib folder
slf4j-api-1.7.2.jar
slf4j-jdk14-1.7.2.jar
The perfect solution which works undoubtedly is to just add these packages to your app:
https://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.7.2
http://archive.apache.org/dist/logging/log4j/1.2.16/
after adding so you may encounter following WARNING which you can simply ignore!
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
credits:
https://www.javacodegeeks.com/2018/02/fix-exception-thread-main-java-lang-noclassdeffounderror-org-slf4j-loggerfactory-java.html
This error occurs because of referenced jars are not checked in our project's order and export tab.
Choose Project ->ALT+Enter->Java Build Path ->Order and Export->check necessary jar files into your project.
Finally clean your project and run.It will run successfully.
When we use the slf4j api jar, we need any of the logger implementations like log4j. On my system, we have the complete set and it works fine.
1. slf4j-api-1.5.6.jar
2. slf4j-log4j12-1.5.6.jar
3. **log4j-1.2.15.jar**
I believe the answer is outlined on the slf4j web-site (Failed to load class org.slf4j.impl.StaticLoggerBinder)
For a very quick solution I suggest adding no-operation (NOP) logger implementation (slf4j-nop.jar)
For example, if using maven:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>${slf4j-nop-version}</version>
</dependency>
I have the same issue for zookeeper start up.
# sh /opt/zookeeper-3.4.13-1.hardtop.0.9.1/bin/zkServer.sh start-foreground
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.13-1.hardtop.0.9.1/bin/../conf/zoo.cfg
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.apache.zookeeper.server.quorum.QuorumPeerMain.<clinit>(QuorumPeerMain.java:67)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 1 more
But the class is already there as part of other slf4j jars:
# grep LoggerFactory lib/*jar
Binary file lib/log4j-1.2-api-2.17.1.jar matches
Binary file lib/log4j-slf4j-impl-2.17.1.jar matches
Binary file lib/netty-all-4.1.30.Final.jar matches
make sure your MANIFEST.MF contains the name of the referenced jar in my application was slf4j-api-*. jar.
You need slf4j-api library. For most cases only slf4j-api and slf4j-jkd14 are only required:
Here you can download the version 1.7.2:
slf4j-api-1.7.2.jar
slf4j-jkd14-1.7.2jar
If you need an example to see how these are used, refers to this tutorial:
http://www.ibm.com/developerworks/java/library/j-hangman-app/index.html
All the code for the tutorial is available
get the compatible version of this jar slf4j-jdk14 and add it as a dependency.
this solved the problem for me.
You need slf4j-api library and slf4j-log4j12-1.7.25 jar. Copy this jars in your project-> WEBINF-> lib folder and in tomcat server lib folder to execute successfully.
When you copy dependency from maven repository there is:
<scope>test</scope>
Try to remove it from dependencies in pom.xml like this.
<!-- https://mvnrepository.com/artifact/ch.qos.logback/logback-classic -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
This works for me. I hope it would be helpful for someone else.
this worked for me /properties/maven uncheck resolve dependencies from Workspace projects.
First, check the dependency hierarchy than to exclude all slf4j jars from other dependencies and add separate slf4j as dependencies.
If it is not maven project then make sure the jar file is inside the project folder. If it is a maven project then make sure it's in the pom.xml.
use maven it will download all the required jar files for you.
in this case you need the below jar files:
slf4j-log4j12-1.6.1.jar
slf4j-api-1.6.1.jar
These jars will also depend on the cassandra version which you are running.
There are dependencies with cassandra version , jar version and jdk version you use.
You can use : jdk1.6
with : cassandra 1.1.12
and the above jars.
If you are facing java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
Add slf4j-log4j12 jar in the library folder of the project
The LoggerFactory class is msising according to the error message:
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
Apparently, the slf4j.jar file is not getting loaded for some reason.

Maven doesn't resolve hibernate-c3p0's dependency on slf4j

When I include hibernate-c3p0 in my Maven's pom.xml file, I get a runtime NoClassDefFoundError as it can't find org.slf4j.impl.StaticLoggerBinder. It was my impression that Maven would resolve this dependency – so if c3p0 requires slf4j, then slf4j would be downloaded and included.
My pom.xml file has:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>3.3.1.GA</version>
</dependency>
It could be that slf4j is an optional dependency. You can check the transitive dependencies very easily using the dependency plugin
mvn dependency:tree
will show you a tree listing of exactly what depends on what. If slf4j is not a dep, you can add it explicity.
HTH
The NoClassDefFoundError for org.slf4j.impl.StaticLoggerBinder indicates that no SLF4J binding could be found. By transitivity, hibernate-c3p0 depends on slf4j-api. However, slf4j-api cannot function without a binding. See SLF4J user manual for details: www.slf4j.org/manual.html
You just need to add one of slf4j-simple, slf4j-log4j12, slf4j-jdk14, or logback-classic as a dependency. The SLF4J manual page mentioned earlier should have the details.

Categories

Resources