maven dependency + local jar in build path = slf4j conflict - java

I try to use the IMPINJ Octane SDK Java which comes as a jar including all needed dependencies together with Spark Framework in a maven project. To include the Spark Framework I use maven and the Octane SDK jar is added to the build path. My pom.xml has only the spark dependency:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>
Every time I try to run the program I get to following error.
Exception in thread "Thread-1" java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
at org.eclipse.jetty.util.log.JettyAwareLogger.log(JettyAwareLogger.java:619)
at org.eclipse.jetty.util.log.JettyAwareLogger.info(JettyAwareLogger.java:314)
at org.eclipse.jetty.util.log.Slf4jLog.info(Slf4jLog.java:74)
at org.eclipse.jetty.util.log.Log.initialized(Log.java:186)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:298)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:288)
at org.eclipse.jetty.util.component.AbstractLifeCycle.<clinit>(AbstractLifeCycle.java:35)
at spark.embeddedserver.jetty.EmbeddedJettyFactory.create(EmbeddedJettyFactory.java:34)
at spark.embeddedserver.EmbeddedServers.create(EmbeddedServers.java:57)
at spark.Service.lambda$init$0(Service.java:342)
at java.lang.Thread.run(Thread.java:745)
The Octane SDK comes with slf4j and the Spark Framework also has slf4j as a dependency but they have different versions. I found the following thread NoSuchMethodError with SLF4J API but since I could remove slf4j from the jar I can't resolve the problem. How can I get this working?
I also tried to exclude slf4j in the pom but it did not work either:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
EDIT (SOLUTION):
I extracted the Octane SDK jar, removed slf4j and compressed it back to a jar.

My understanding is that sparks requires slf4j 1.7.13.
Then, you add Octane to the classpath (not through a maven dependency) and this Octane jar contains older classes of slf4j.
I just downloaded Octane to see for myself. I notice it include 2 versions:
OctaneSDKJava-1.22.0.30.jar
OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar
You need to use OctaneSDKJava-1.22.0.30.jar and manually include all other dependencies but NOT the slf4j one (or the opposite, use OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar and remove slf4j).
EDIT to answer a question in the comments:
I opened the latest OctaneSDKJava-1.26.2.0-jar-with-dependencies.zip, which contains a README.txt with the following details:
DEPENDENCIES
RUNTIME DEPENDENCIES
jdom 1.0 http://www.jdom.org
log4j 1.2.15 http://logging.apache.org/log4j/1.2/download.html
jargs 1.0 http://sourceforge.net/project/showfiles.php?group_id=33024
mina 1.1.7 http://mina.apache.org
slf4j-log4j12 1.5.0 http://www.slf4j.org
slf4j-api 1.5.0 http://www.slf4j.org
xerces-j 2.4.0 http://xerces.apache.org/
COMPILE DEPENDENCIES
velocity-dep 1.5 http://velocity.apache.org
jalopy 0.3.1 http://jalopy.sourceforge.net
jdom 1.0 http://www.jdom.org
log4j 1.2.15 http://logging.apache.org/log4j/1.2/download.html
commons-collection 3.2 http://commons.apache.org
commons-configuration 1.5 http://commons.apache.org
commons-lang 2.3 http://commons.apache.org
common-logging 1.1.1 http://commons.apache.org
JAXB RI dependencies including:
jaxb-xjc 2.0 https://jaxb.dev.java.net/
jaxb-impl 2.0 https://jaxb.dev.java.net/
jaxb-api 2.0 https://jaxb.dev.java.net/
activation 2.0 https://jaxb.dev.java.net/
jsr173_1.0_api 2.0 https://jaxb.dev.java.net/
The five above jaxb dependencies are available in a single jar "JAXB
RI" from https://jaxb.dev.java.net/. Execute this jar (doubleclick
windows, "java -jar " all other platforms) and copy the
individual jars to the LTKJava/lib directory) plus above runtime
dependencies
TEST DEPENDENCIES
JUnit 4.4 http://sourceforge.net/project/showfiles.php?group_id=15278
plus above dependencies note that the junit dependency needs to be
placed in the ANT_HOME/lib directory

Related

JDK 10 cannot import javax.xml.namespace in Eclipse

It's very strange. I am moving a dynamic web project from Java 8 to Java 10.
The last thing I cannot get the dependency resolved is the javax.xml.namespace.QName class.
You can see in the attached screen shot, the QName class exist in JRE System Library, but the IDE keep complaining that QName cannot be resolved to a type.
There probably is a duplicate dependency pulled in from some other dependency.
In eclipse do
"Navivate -> Open Type..."
Type in "java.xml.namespace".
If there are other results than from your (Open-)JDK, these need to be removed in the following steps. In my case it was xml-apis
Open your pom.xml in eclipse, and visit the "Dependency Hierarchy" tab to check which dependency was pulling in xml-apis
Type "xml-apis" in the Filter. In my case the top level dependency that was pulling xml-apis was "esapi"
exclude xml-apis from the esapi dependency:
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.2.0.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
Right click your Project and choose "Maven -> Update Project...". Check your project and click OK.
That's it
I had the same error moving from Java 8 to Java 11,
and I included an explicit dependency on the library stax-api 1.0-2:
<dependency>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<version>1.0-2</version>
</dependency>
and excluded any transitional dependency on the library stax-api 1.0.1:
...
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
...
After this, my IDE found the lost import javax.xml.namespace.QName correctly.
I hope this helps.
Try to change the order of elements on your classpath. The JRE must be before the Maven Dependencies. That fixes the issue.
My guess is that the Java 10 compiler notices that you're trying to replace internal classes (java.xml.namespace) with code from JARs and it doesn't like that.
Resolved it by removing jsr173_api.jar from the project classpath (project -> properties -> java build path -> libraries -> classpath). It appears again when eclipse project rebuilt.
This worked! Checking for multipletypes Ctrl+Shift+T, removing unwanted ones.
I have had the same experience with the JRE 11, and Gradle 7.5. If it helps anyone, you can exclude xml-apis as such:
configurations {
all {
exclude group: 'xml-apis', module: 'xml-apis'
}
}

Forcing maven spring boot project to use older version of a dependency instead of a new version from another dependency

I'm running in to a problem where I cannot start a spring boot server due to the same problem listed in this question:
How to set up Spring Boot and log4j2 properly?
I am encountering this scenario because the spring boot project has a dependency on a jar that includes elasticsearch, which includes a new version of slf4j that isn't compatible with spring boot
I tried the recommended solution by implementing every exclusion in the elasticsearch project dependency definition possible, but for some reason the new version keeps being picked up. I cannot seem to force the spring boot project to ignore the logging packages used by the elasticsearch project.
Here is my pom for the spring-boot project, see the dependency for problematic.project.import : http://pastebin.com/Yeq2qk9Y
Here is the pom for the project that is being imported into the spring boot project: http://pastebin.com/gknmf6Tt
The error I am getting is:
Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(Lorg/apache/logging/log4j/core/config/ConfigurationSource;)Lorg/apache/logging/log4j/core/config/Configuration;
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadConfiguration(Log4J2LoggingSystem.java:165)
at org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.loadDefaults(Log4J2LoggingSystem.java:148)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:75)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50)
Any tips on how to get this issue cleared? Is this possible for two versions of this set of libraries to be loaded, each module ignorant to the version they don't need?
You can exclude the cyclic dependencies by using the <exclusions> tag in your pom.xml like this:
<dependency>
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>sample.ProjectE</groupId> <!-- Exclude Project-E from Project-B -->
<artifactId>Project-E</artifactId>
</exclusion>
</exclusions>
</dependency>
You should exclude the cyclic dependency of the newer version from the dependency which is having it and that way only the older version will be loaded and not both.
Here is the link for more information:
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

Getting java.lang.NoClassDefFoundError: org/bouncycastle/asn1/DEREncodable during PDF Encryption [duplicate]

I'm trying to use iText Java.
When you run the example "how to sign" the following error occurs:
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.tsp.TimeStampTokenInfo
According "Getting Started with iText - How to sign a PDF using iText", I have to use the BouncyCastle.
I downloaded the file: bcprov-jdk15on-147.jar from BouncyCastle download page.
And added to the project: Java Build Path/Libraries/Add External JARs...
I added the following line:
Security.addProvider(new BouncyCastleProvider());
When you run the example the same error occurs.
So I downloaded another file: bcpkix-jdk15on-147.jar entitled "PKIX/CMS/EAC/PKCS/OCSP/TSP/OPENSSL"
And added to the project: Java Build Path/Libraries/Add External JARs...
Now I have two Jars.
When you run the example the following error occurs:
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.DEREncodable
I tried downloading the file "bcprov-ext-jdk15on-147.jar" but did not solve the problem.
I am using iText 5.2.1 and eclipse on Windows 7 64 bits.
iText marks bouncycastle dependencies as optional. If you require them, you need to add the dependencies in your own pom file.
To find out which dependency to include in your project, open the itextpdf pom.xml file of the version you are using (for example 5.3.2, here) and search for the 2 bouncycastle dependencies.
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.47</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15on</artifactId>
<version>1.47</version>
<optional>true</optional>
</dependency>
Copy them into your pom file and remove the optional option.
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.47</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk15on</artifactId>
<version>1.47</version>
</dependency>
BouncyCastle libs are undergoing heavy API changes that broke the compatibility with other libs like iText.
Either
use a previous version of BouncyCastle libs. Old versions can be found here. However, you'll have to find the right version of iText that was compatible with this particular version of BC.
make your own build of iText (the SVN trunk has been fixed). iText can be build with Maven (there's a short readme file at the root of the SVN). Please note that it's at your own risk, there may be bugs in trunk.
wait for the next version of iText. From my experience, iText releases come every couple of months, sometime more often, sometimes less. I'm not an iText committer though, so I can't give you any ETA.
More information can be found in this thread
With itextpdf version 5.5.4 org.bouncycastle dependencies are marked as <optional>true</optional>. This means you MUST include those dependencies in your own pom, or you can run into classnotfound exceptions.
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.4</version>
</dependency>
<!-- Bouncycastle dependencies necessary as they are optional = true
in itextpdf ... but they're not-so-optional in reality -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.49</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.49</version>
</dependency>
from version of bcprov-jdk15on-147, class of DEREncodable is no longer exist under the path of org.bouncycastle.asn1. You can use version before 146 (including 146) to resolve this question.
It's strange that the jars available at bouncycastle.org don't seem to contain this class. Perhaps, you may want to use one from the locations listed in this page (link).
i have the same problem, but a fix it when i download the libreria and update those files on /WEBINF/LIB
Luckily, the dependency jars are being delivered along with the iText now.
Please check the repository link below and download extrajars.zip file
http://sourceforge.net/projects/itext/files/
For jruby-ers with the same failure, I updated to jruby-complete-9.1.13.0.jar from jruby-complete-1.6.6.jar and the problem seemed to resolve...FWIW...

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