Can not upgrade infinispan to 9.1.0.Final: ClassCastException - java

I am trying to upgrade infinispan from 8.2.4.Final to 9.1.0.Final, but get some errors from embedded slf4j while building tomcat war-file.
Logs:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in
[jar:file:/C:/tomcat/webapps/ROOT/WEB-INF/lib/infinispan-embedded-9.1.0.Final.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/C:/tomcat/webapps/ROOT/WEB-INF/lib/logback-classic-1.1.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation.
SLF4J: Actual binding is of type
[org.jboss.slf4j.JBossLoggerFactory] 20-Jul-2017 16:07:34.170
ERROR
[RMI TCP Connection(5)-127.0.0.1]
com.myapp.context.LogbackLoggingConfigurator.configureLoggingExternal
Loading logger configuration from C:\my-files\conf\logback.xml
java.lang.ClassCastException: org.jboss.slf4j.JBossLoggerFactory
cannot be cast to ch.qos.logback.classic.LoggerContext
The code, mentioned in logs:
public void configureLogging(final URL config) {
final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
lc.reset();
final JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
configurator.doConfigure(config);
} catch (final JoranException je) {
logger.error("Unable to configure logback", je);
}
StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
And wrong line is here: final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
Firstly, I excluded slf4j-api from "infinispan-embedded" dependency, but unsuccessfully because slf4j is hardcoded.
Secondly, I added <packagingExcludes>WEB-INF/lib/infinispan-embedded-9.1.0.Final.jar!/org/slf4j/impl/StaticLoggerBinder.class</packagingExcludes> to maven-war-plugin (maybe with '!' symbol we cannot get access to nested jars, but I don't find another variants). Attempt was failed.
So, how can I fix this exception? Maybe it is possible to use maven-shade-plugin? But it seems unacceptable for my project.

I have some problem. I solve it with a trick. I exclude logback from dependencies. I used infinispan-embedded as logger. But I think it is not right way to solve the problem. I think "http://infinispan.org/" developers need to export codes about logger as another jar. Then we can exclude in maven. Actually It is not right way to be dependent logger jar because of another task.

I have some problem. I solve it with a trick. I exclude logback from dependencies. I used infinispan-embedded as logger. But I think it is not right way to solve the problem. I think "http://infinispan.org/" developers need to export codes about logger as another jar. Then we can exclude in maven. Actually It is not right way to be dependent logger jar because of another task.
I wrote to infinispan team and they quick respond. As they said infinispan-embedded is "uber-jar" it is mean "all dependencies in one". You can use each dependencies of infinispan instead of it. infinispan-core and which you want to use.
You can see detail of the opened issue by clicking on this link https://developer.jboss.org/message/975209?et=watches.email.thread#975209
on jboss website.

Related

Package dependencies in a jar

I'm trying with a .jar library but the init method has a call to slf4j. I have added slf4j to my dependencies Project but I believe that I need to repackage the library with the dependency inside the jar.
The method I'm calling in the jar has this line:
private static final org.slf4j.Logger LOG =
org.slf4j.LoggerFactory.getLogger(Init.class);
But I have this error:
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.
You also need an slf4j implementation, just as your error said. There are multiple. Here are a two:
slf4j-simple: it prints out to your console/terminal
log4j-slf4j-impl: The Apache Log4j SLF4J API binding to Log4j 2 Core
If you need just the .jar, choose your needed version and you can download it under files.
If you need more help, the official manual explains it quite good.
Hope I could help you

Multiple SLF4J bindings

I have two jar files in my classpath which has a dependency with slf4j. This causes a warning message in my Java program:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/lib/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/lib/myprogram.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Is there a way to remove this warning message by only changing the gradle file, and without removing any of above jar files from my classpath?
Thanks
Is there a way to remove this warning message by only changing the gradle file, and without removing any of above jar files from my classpath?
No.
The only way to remove that warning is by providing only a single binding for SLF4J. And you really should do so:
Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it. The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random.
Since you provide a binding in your own jar, the easiest way to restrict yourself to a single binding would be to exclude the slf4j-log4j12-1.7.6.jar.

how to fix and execute this sample Hibernate program for create table

I have a simple hibernate program in java. It is throwing an exception and I can't understand.
My code is :
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class TestEmployee {
public static void main(String[] args) {
AnnotationConfiguration config = new AnnotationConfiguration();
config.addAnnotatedClass(Employee.class);
config.configure("hibernate.cfg.xml");
new SchemaExport(config).create(true, true);
}
}
The error is :
SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x
Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.impl.StaticLoggerBinder.getSingleton()Lorg/slf4j/impl/StaticLoggerBinder;
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:197)
at com.Hibernate.chapter1.TestEmployee.main(TestEmployee.java:10)**
Note : There is a line on AnnotationConfiguration() in my eclipse.
What is the cause and How do I fix it?
The reason for your problem is given clearly with the error
SLF4J: slf4j-api 1.6.x (or later) is incompatible with this binding.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x
An SLF4J binding designates an artifact such as slf4j-jdk14.jar or slf4j-log4j12.jar used to bind slf4j to an underlying logging framework, say, java.util.logging and respectively log4j.
Mixing mixing different versions of slf4j-api.jar and SLF4J binding can cause problems. For example, if you are using slf4j-api-1.7.12.jar, then you should also use slf4j-simple-1.7.12.jar, using slf4j-simple-1.5.5.jar will not work.
From the client's perspective all versions of slf4j-api are compatible. Client code compiled with slf4j-api-N.jar will run perfectly fine with slf4j-api-M.jar for any N and M. You only need to ensure that the version of your binding matches that of the slf4j-api.jar. You do not have to worry about the version of slf4j-api.jar used by a given dependency in your project. You can always use any version of slf4j-api.jar, and as long as the version of slf4j-api.jar and its binding match, you should be fine.
To make hibernate work you would have added hibernate related jar files to your project. It includes jars whose names start with "slf4j". To fix the error you need to make sure all slf4j jars are of same version.ie ( if you are using slf4j-api-1.7.12.jar, then you should also use slf4j-simple-1.7.12.jar, using slf4j-simple-1.5.5.jar will not work. )
Updating all your slf4j jars to latest version should fix this or you could check all slf4j jars and replace the offending one.
The link to download the slf4j is below
http://www.slf4j.org/download.html
More about the error and jar can be found at
http://www.slf4j.org/codes.html

View Logger output in eclipse for a java project

in one of my elicpse project I have come across this logger related snippet, I noticed that it is from slf4j library.
private static final Logger logger = LoggerFactory
.getLogger(someclass.class);
Then in some point of the code i noticed this,
logger.debug("Found {} object",
numberofobject);
My question is, when I run the program I do not see the logger output, how can I see that in eclipse?
You need to properly configure the binding for slf4j. slf4j is just a facade, not a logging tool.
Since 1.6.0 if no binding is found on the class path, then SLF4J will default to a no-operation implementation.
Have a look at the officiel manual here on how to configure slf4j.
you need to add a logging library to your project that implements the slf (just as Burkhard mentioned)
You need to configure the logger of your choice to log debug messages to the console (e.g. with a console appender in log4j)

failed to load class 'org.slf4j.impl.StaticLoggerBinder'

I created a jar file with all the dependencies, and I implemented the logging using slf4j + logback. Thus I have a logback.xml file defined for all the loggers. However when I run the jar it gave me this message:
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.
I dont see any logging happening. After I unzip the jar file, I can see the org.slf4j folder. I don't know why this is not working.
From http://www.slf4j.org/codes.html#StaticLoggerBinder (the link in the message):
This error is reported when the org.slf4j.impl.StaticLoggerBinder
class could not be loaded into memory. This happens when no
appropriate SLF4J binding could be found on the class path. Placing
one (and only one) of slf4j-nop.jar, slf4j-simple.jar,
slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class
path should solve the problem. SINCE 1.6.0 As of SLF4J version 1.6, in
the absence of a binding, SLF4J will default to a no-operation (NOP)
logger implementation. You can download SLF4J bindings from the
project download page.
In other words, you need a slf4j backend in your classpath, e.g. logback.
It seems logback-classic.jar is missing from classpath.
Take a look at http://slf4j.org/manual.html#swapping.
Is this a scala project? If yes then adding the below dependency will help. It worked for me.
"org.slf4j" % "slf4j-simple" % "1.7.12"

Categories

Resources