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>
I have a java application that uses bytedeco/javacv library.
but when I run the application, I am getting the following exception.
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.bytedeco.javacpp.Loader.load(Loader.java:386)
at org.bytedeco.javacpp.Loader.load(Loader.java:354)
at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2719)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:391)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:385)
at com.diyoron.ai.examples.VideoFrameProccessor.main(VideoFrameProccessor.java:38)
Error getting static method ID of org/bytedeco/javacpp/Loader/putMemberOffset
The code is as following,
String videoPath = video.getAbsolutePath();
FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(videoPath);
grabber.start();
According to this following statement in the README.MD
Additionally, we need to either set the javacpp.platform system
property (via the -D command line option) to something like
android-arm, or set the javacpp.platform.dependencies one to true to
get all the binaries for Android, Linux, Mac OS X, and Windows. On
build systems where this does not work, we need to add the
platform-specific artifacts manually. For examples with Gradle and
sbt, please refer to the README.md file of the JavaCPP Presets.
Another option available for Scala users is sbt-javacv.
~ Reference GitHub.
I added argument -Djavacpp.platform.dependencies="true", But still I am getting the exception. I am not sure what is causing this issue, I have very less experience in working with c++ wrappers.
PS: I have not installed any c++ dependencies/libraries or open-cv in my machine.
And all the solutions are related to Android and I haven't had much luck following those in my java related application.
Adding the following dependencies resolved the issue.
<!-- http://mvnrepository.com/artifact/org.bytedeco/javacv -->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.2</version>
</dependency>
<!-- http://mvnrepository.com/artifact/org.bytedeco/javacpp -->
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>3.1.0-1.2</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg</artifactId>
<version>3.0.2-1.2</version>
</dependency>
My java code is dependent on 2 libraries A and B
A has a dependency on GoogleCollections
B has a dependency GoogleGuava r10;
Now when i build my code everything works fine.But when i run i get following exception
java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.copyOf([Ljava/lang/Object;)Lcom/google/common/collect/ImmutableList;
at com.abc.Pqr$Builder.withXYZ(ExponentialBackoffRetryPolicy.java:329)
How can i solve this problem?
Google Collections has been deprecated and moved into Guava. Exclude it from A. With Maven, you do that with the exclusions tag below the dependency tag in your project's POM:
<dependency>
<groupId>org.project</groupId>
<artifactId>library-a</artifactId>
<version>[version]</version>
<exclusions>
<exclusion>
<!-- whatever the correct values are -->
<artifactId>google-collections</artifactId>
<groupId>google-collections</groupId>
</exclusion>
</exclusions>
</dependency>
If your lucky.... include only the most recent version version of GoogleCollections that contains ImmutableList that you depend upon..
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.
I'm working on an Android app using Maven as the build tool. I managed to set evertyhing up correctly (maven dependencies are exported to the apk etc.), however I have one remaining problem which is driving me crazy.
I want to include a dependency on simpleframework's xml parser defined as follows in my POM file:
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.5.3</version>
</dependency>
When I issue mvn install on the project, I get the following error (truncated):
trouble processing "javax/xml/namespace/NameSpaceContext.class" ...
I know the error results from the simple xml parser referencing these javax-classes, however I haven't found a solution yet (setting the --core-library flag is of no use).
I'm currently trying to repack the dependency with the maven-jarjar-pluging but this doesn't seem to work either.
Can anyone help me out with this? Many, many thanks in advance!
Define your simple-xml depedency like this :
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.6.1</version>
<exclusions>
<!-- StAX is not available on Android -->
<exclusion>
<artifactId>stax</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<!-- Provided by Android -->
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
</exclusions>
</dependency>
I use android-maven-plugin, and adding <coreLibrary>true</coreLibrary> to the <configuration> tag of the plugin in the POM works for me. However, there's a bug: https://github.com/jayway/maven-android-plugin/pull/34, that you need to include to fix the plugin you are using, since the bug won't be fixed until 3.0. Here's how I got it working for me using 2.9.0-SNAPSHOT.
add a pluginRepository pointing to http:// oss.sonatype.org/content/repositories/jayway-snapshots/ to get 2.9.0-SNAPSHOT
update your plugin version to use 2.9.0-SNAPSHOT and add <coreLibrary>true</coreLibrary> to pom.xml
get the fix: git clone https://github.com/kevinpotgieter/maven-android-plugin.git
remove src/test/java/com: so the test won't fail
mvn package
copy it and overwrite your local maven cache in .m2 (You may need to remove your plugin repository yours gets overwritten every time.)
Step 3-6 won't be necessary after the fix gets into 2.9.0-SNAPSHOT.
Update July 2010: 2.9.0-beta-4 has the fix, so you don't need the above workaround if you use 2.9.0-beta-4 or later. I tested 2.9.0-beta-5 which worked just fine.
Spring Android uses Maven to integrate Simple. Take a look at the following URL, it should provide pointers on how to get Maven working with Simple.
http://static.springsource.org/spring-android/docs/1.0.x/reference/html/rest-template.html