Dependent JARS for producing RESTful JSON - json

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

Related

Error Implementing lib module dependency by creating .aar file in build-gradle (app) file

I am facing the following issue whenever I try to implement the .aar file instead of the direct lib module dependency.
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugCompileClasspath'.
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find :xxxlib-release:.
N:B: I have configured the library project for jitpack also with the publishing config. A few days back, there was no issue but now I am getting errors for both the .aar and jitpack versions of my library which I guess is related. Additionally, I have upgraded to Android Studio Bumblebee and using targetSdkVersion 29 or 30; kotlin = 1.6.0 and classpath 'com.android.tools.build:gradle:7.0.3'
I can't find out what am I missing here. Any help will be appriciated, thanks.

java.lang.No classDefFound error while using PEXML for android in Libgx

I am using PEXML library for giving physics to bodies in my game. It worked very well in desktop but when I ran in android it is giving me error at code
playerPhysics = new PEXML(Gdx.files.internal("data/physics.xml").file());
and showing error
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/bind/JAXBContext; at com.hi5dev.box2d_pexml.PEXML.loadXML(PEXML.java:124) at com.hi5dev.box2d_pexml.PEXML.(PEXML.java:24)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.xml.bind.JAXBContext" on path: DexPathList[[dex file "/data/data/com.myplayer.football/files/instant-run/dex/slice-slice_9...
Google search shows javax.xml.bind.JAXBContext is in the file javax.xml.bind.jar
Java needs to find this file at runtime. It looks for it in your Java classpath ( set of directories ).
You need this Jar to be in your runtime classpath
The error you wrote about shows you the classpath.
You can either
put javax.xml.bind.jar in the current classpath
or
Modify the classpath to include the location of javax.xml.bind.jar
Lookup how to modify the Java classpath for your operating system.

Handlebars-proto and logstash-logback-encoder slf4j conflict

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?

Glassfish Embedded does not start

My glassfish 3.2 embedded was starting with Arquillian and Junit perfectly and now I've getting this Exception in eclipse.
I've replace .m2 repository and it doesn't start.
Anybody could help me:
java.lang.RuntimeException: Could not setup GlassFish Embedded Runtime
Caused by: org.glassfish.embeddable.GlassFishException: A MultiException has 2 exceptions.
1. java.lang.IllegalArgumentException: The scope name given in the descriptor (org.glassfish.hk2.api.PerLookup) did not match the scope annotation on the class (javax.inject.Singleton) in class CommandExecutorImpl
2. java.lang.IllegalArgumentException: Errors were discovered while reifying SystemDescriptor(
implementation=com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl
contracts={com.sun.enterprise.admin.cli.embeddable.CommandExecutorImpl,org.glassfish.embeddable.CommandRunner
at com.sun.enterprise.glassfish.bootstrap.StaticGlassFishRuntime.newGlassFish(StaticGlassFishRuntime.java:138)
at org.jboss.arquillian.container.glassfish.embedded_3_1.GlassFishContainer.setup(GlassFishContainer.java:138)
... 62 more
I've solved this question deleting all workspace project and eclipse .metadata and RemoteSystemsTempFiles folders, after that I've dowloaded all project with "Checkout Project" and the glassfish-embedded using Junit 4 have started normally.

Jruby log4j integration

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.