My project uses handlebars-proto to bind templates to json. Also i am trying to use logstash-logback-encoder to log in form of Json for logstash. Below are my compile dependencies ( along with other dependencies)
compile 'net.logstash.logback:logstash-logback-encoder:4.6'
compile 'com.github.jknack:handlebars-proto:4.0.5'
If I remove handlebars dependency logging works fine. If handlebars is present I get the below warning :
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found
binding in
[jar:file:/C:/Users/manish/.gradle/caches/modules-2/files-2.1/com.github.jknack/handlebars-proto/4.0.5/5979737344d99e0d8b482e828f247ae86fd0113/handlebars-proto-4.0.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in
[jar:file:/C:/Users/manish/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.6/665e3de72f19ec66ac67d82612d7b8e6b3de3cd0/logback-classic-1.1.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an
explanation.
followed by error :
Failed to instantiate [ch.qos.logback.classic.LoggerContext] Reported
exception:
java.lang.NoSuchMethodError: ch.qos.logback.core.spi.ContextAwareBase.(Lch/qos/logback/core/spi/ContextAware;)V
at
net.logstash.logback.composite.CompositeJsonFormatter.(CompositeJsonFormatter.java:106)
at
net.logstash.logback.composite.loggingevent.LoggingEventCompositeJsonFormatter.(LoggingEventCompositeJsonFormatter.java:28)
at
net.logstash.logback.LogstashFormatter.(LogstashFormatter.java:122)
at
net.logstash.logback.LogstashFormatter.(LogstashFormatter.java:118)
at
net.logstash.logback.LogstashFormatter.(LogstashFormatter.java:114)
at
net.logstash.logback.encoder.LogstashEncoder.createFormatter(LogstashEncoder.java:31)
at
net.logstash.logback.encoder.CompositeJsonEncoder.(CompositeJsonEncoder.java:48)
at
net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder.(LoggingEventCompositeJsonEncoder.java:23)
at
net.logstash.logback.encoder.LogstashEncoder.(LogstashEncoder.java:27)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method) at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at java.lang.Class.newInstance(Class.java:379) at
ch.qos.logback.core.joran.action.NestedComplexPropertyIA.begin(NestedComplexPropertyIA.java:122)
at
ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:276)
at
ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:148)
at
ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:130)
at
ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
I tried excluding slf4j as transitive dependency from handlebars but
it did not help.
compile
('com.github.jknack:handlebars-proto:4.0.5'){
exclude module: 'slf4j-api'
}
Thanks in advance for help. Let me know if more details are required.
The error message is because the handlebars-proto jar contains an implementation of org.slf4j.impl.StaticLoggerBinder, which means that it has a logging implementation. You are also trying to add your own logging implementation of Logback, and since SLF4J can't use two logging systems at once, it's complaining.
I'm not familiar with the handlebars project, but I'm guessing that the library you have there is a full application that includes a logging system, and not really designed to be used as a dependency by another project. Perhaps there's a different version available that is just the library, and that doesn't try to include its own logging implementation?
Related
I have written a RESTful service in java and want to produce json out of the get method. I was struggling with many no class def found error due to issues in jar versions or dependencies.
For example
Jackson error: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/Versioned
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingException$Reference
I have created a dynamic web project in eclipse and added the jars in classpath and Maven is not used here.
Any idea on the list of dependent jars ??
I have finally found the jar versions and dependencies
I'm at my wit's end here - never seemed to have faced this problem. I find it relatively easy to set up quick HelloWorld applications to ensure Restlet 2.0 is up and running. However, I'm facing a strange exception which I've never encountered before. I have the jars in my classpath as well as the WEB-INF/lib folder but for some reason I keep getting the following exception:
INFO: Unable to register the helper org.restlet.ext.json.JsonConverter
java.lang.NoClassDefFoundError: org/json/JSONException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.restlet.engine.Engine.registerHelper(Engine.java:718)
at org.restlet.engine.Engine.registerHelpers(Engine.java:753)
at org.restlet.engine.Engine.registerHelpers(Engine.java:793)
at org.restlet.engine.Engine.discoverConverters(Engine.java:501)
at org.restlet.engine.Engine.<init>(Engine.java:337)
at org.restlet.engine.Engine.register(Engine.java:248)
at org.restlet.engine.Engine.register(Engine.java:237)
at org.restlet.engine.Engine.getInstance(Engine.java:149)
at org.restlet.engine.Engine.getLogger(Engine.java:204)
at org.restlet.Context.<init>(Context.java:160)
at org.restlet.Context.<init>(Context.java:133)
at org.restlet.ext.servlet.ServerServlet.createComponent(ServerServlet.java:422)
at org.restlet.ext.servlet.ServerServlet.getComponent(ServerServlet.java:763)
at org.restlet.ext.servlet.ServerServlet.init(ServerServlet.java:881)
at javax.servlet.GenericServlet.init(GenericServlet.java:242)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1428)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:1060)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:187)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:959)
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1430)
... 45 more
The following jars are in my classpath and the WEB-INF/lib folders:
org.json.jar
org.restlet.jar
org.restlet.ext.servlet
org.restlet.ext.json
I'm building the project using Eclipse and deploying on Glassfish. The web.xml etc are all fine and no deployment errors...however, this one has had me scratching my head for a while.
Any ideas?
I had the same or a similar problem. I want to override the jackson representation and remove some dependencies it imports but when I do, the jackson converter is not discovered.
Then I've found why in my case: the jar contains a META-INF/services folder with a file called org.restlet.engine.converter.ConverterHelper. That's how discovery works.
I've tried to add that files to my path and it didn't work, don't know. So I ended up registering the Jackson converter
Engine.getInstance().getRegisteredConverters().add(new JacksonConverter());
For some reason the error went away when I swapped the file with that from the Restlet Distribution - in the org.json folder of the Restlet Java EE version.
Seems maybe something was missing in the org.json.jar that I had from the json website, don't know...
It looks like your application isn't able to find a library. If you're building your app in Eclipse, have you made sure that the libraries are being exported? Go to the Build Path section, and make sure the checkbox for exporting libraries is checked.
I am trying to use quartz in a simple example in project. I am getting the following exception, I am not sure what it means...However I updated my slf4j to 1.6.1 in my POM file even then this still appears,
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.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:131)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:395)
at org.quartz.impl.StdSchedulerFactory.<init>(StdSchedulerFactory.java:249)
............
Any help on this would be highly appreciated. Thanks.
You need all your SLF4J dependencies to use the same version.
SLF4J: Your binding is version 1.5.5 or earlier.
SLF4J: Upgrade your binding to version 1.6.x. or 2.0.x
If you look at your dependency tree, I expect that you'll find more then one version of SLF4J for the various jar it uses.
For example
[INFO] +- org.hibernate:hibernate-core:jar:3.5.3-Final:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile (version managed from 2.7.6)
[INFO] | \- org.slf4j:slf4j-api:jar:1.5.8:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.8:compile
Here the two slf4j deps have the same version.
Looks like the SLF4J binding used inside quartz is too old. You should exclude the old version from quartz and add a new one explicitly to your project. Run mvn dependency:tree and post your result here. I will be able to give you exact instructions then.
I am currently working on integrating Java application General Architecture For Text Engineering (GATE) with a Rails application using JRuby architecture. When we worked on integrating JRuby with log4j, I am getting following error:
0 [main] DEBUG Main.class - Hello world
gate/Gate.java:80:in `<clinit>': java.lang.NoClassDefFoundError: org/apache/log4
j/Logger (NativeException)
from gateapp/Main.java:86:in `main'
from test.rb:12
test.rb is the name of ruby program.
I tried importing all the log4j apache libraries, and included the class file in the test.rb file.
When I run the Java program alone its running fine. But when I generate the jar file and include them in Ruby file (test.rb) , I am getting this error
java.lang.NoClassDefFoundError: org/apache/log4j/Logger (NativeException) problem is occuring. How to deal with this problem ?
You need to make sure the log4j JAR file is in your classpath. One way to do this is to set the CLASSPATH variable in your environment. Another way would be to call require in your ruby code like
require "/some/path/MyStuff.jar"
Here is my config to set it up with couchbase Java SDK
include Java
def setup_log4j
java::lang.System.setProperty("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.Log4JLogger")
fa = Java::OrgApacheLog4j::FileAppender.new();
fa.setName("FileLogger");
fa.setFile("./log/#{Rails.env}.log");
fa.setLayout(Java::OrgApacheLog4j::PatternLayout.new("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Java::OrgApacheLog4j::Level::INFO);
fa.setAppend(true);
fa.activateOptions();
Java::OrgApacheLog4j::Logger.getRootLogger().addAppender(fa)
end
Just beware that I required the lo4j.jar file earlier.
Worth to mention that there is project named log4jruby.
I have a groovy application running locally on my desktop.
Apparently it runs error free. At least all unit tests I wrote are fulfilled.
I want to deploy the application using a war file. For this I use the command
grails war
in the home directory of the application. When doing this I am getting the following exception:
Error executing script War: java.lang.NullPointerException
gant.TargetExecutionException: java.lang.NullPointerException
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:331)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy:334)
at gant.Gant$_dispatch_closure6.doCall(Gant.groovy)
at gant.Gant.withBuildListeners(Gant.groovy:344)
at gant.Gant.this$2$withBuildListeners(Gant.groovy)
at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
at gant.Gant.dispatch(Gant.groovy:334)
at gant.Gant.this$2$dispatch(Gant.groovy)
at gant.Gant.invokeMethod(Gant.groovy)
at gant.Gant.processTargets(Gant.groovy:495)
at gant.Gant.processTargets(Gant.groovy:480)
Caused by: java.lang.NullPointerException
at _GrailsWar_groovy$_run_closure5_closure25_closure26_closure28.doCall(_GrailsWar_groovy:289)
at _GrailsWar_groovy$_run_closure5_closure25_closure26_closure28.doCall(_GrailsWar_groovy)
at _GrailsWar_groovy$_run_closure5_closure25_closure26.doCall(_GrailsWar_groovy:282)
at _GrailsWar_groovy$_run_closure5_closure25_closure26.doCall(_GrailsWar_groovy)
at _GrailsWar_groovy$_run_closure5_closure25.doCall(_GrailsWar_groovy:258)
at _GrailsWar_groovy$_run_closure5.doCall(_GrailsWar_groovy:256)
at _GrailsWar_groovy$_run_closure4.doCall(_GrailsWar_groovy:239)
at War$_run_closure1.doCall(War.groovy:38)
at gant.Gant$_dispatch_closure4.doCall(Gant.groovy:324)
... 10 more
Any hint why?
Thanks a lot in advance
I think you'll have to find the source of Gant.groovy and see what it's doing on that line. Apparently there is some problem caused by your project's specific configuration (since such a show-stopper bug would have been caught if it always occurred), but the error message does not contain much information.
Alternatively, you could try upgrading Grails to the latest version 1.1.1 if you haven't already.