JNI NoClassDefFoundError in springboot executable jar - java

I have springboot application which is connecting to client shared dynamic library using jni.
There is one **callback method **which is registered to dll using ine register function.
This method is invoked on some events from dll.
When executed as java application from intellij, this works fine but when executed **as jar **and when this callback method is invoked its throwing **NoClassDefFoundError ** as below
java.lang.NoClassDefFoundError: com/test/Sample
Caused by: java.lang.ClassNotFoundException: com.test.Sample
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java: 424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
By default springboot puts all classes inside BOOT-INF folder.
When I manually modified jar and added this class outside BOOT-INF i.e at rootLevel it worked.
Like below:
BOOT-INF
com
META-INF
org
In above snippet com is directory inside which Sample class was present under subpackage test.
springboot version used: 2.3.6.RELEASE
Using springboot-maven-plugin to create executable jar

Related

java.lang.NoClassDefFoundError on Docker

When The Program is Ran in the Local PC, it is working fine, but if it is running in the docker throws the following error:
Exception in thread "Thread-16" java.lang.NoClassDefFoundError: org/apache/kafka/common/serialization/Serializer
at org.eclipse.kura.example.configurable.ConfigurableExample$1.run(ConfigurableExample.java:52)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: org.apache.kafka.common.serialization.Serializer cannot be found by org.eclipse.kura.example.configurable_1.0.0.202201251713
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:484)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:395)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:387)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:150)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 2 more
But this is working fine in the LocalMachine.
What is the issue ?
This may be debugged in following ways:
Ensure that you have all the required dependencies inside your docker container. You may want to check your docker base image first.
Check if you have set the classpath appropriately to include that jar file (kafka-clients).
Validate your entrypoint/cmd which you use to start the service to check if it has the appropriate classpath.
Check your classloader and see why it is not able to load that class.
If your executable is a fat jar file, check if that jar file contains the kafka-clients library where that class is present.

java.lang.ClassNotFoundException while instrumenting eclipse rcp application

I tried injecting a method call statement using javassist in every method of some desired classes. The statement corresponds to a class in the java-agent jar. For example if my agent has class like a.b.HelperClass, I am injecting a.b.HelperClass.call(); in the beginning of every class using javassist.
I tried with a spring boot web app and the agent works fine but with RCP application it is throwing
java.lang.ClassNotFoundException: a.b.HelperClass
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Do I need to load the classes residing inside agent-jar using the eclipse class loader? BTW I'm instrumenting by calling agent-main method and not premain.
Eclipse is OSGi based and has a module system that is enforced.
The HelperClass must be in the classpath of the Eclipse Plugin where it should be used.

Failure while deploying EAR file on Jboss Wildfly

I've got an EAR file which contains two wars and multiple jars. I'm using maven-ear-plugin to generate this file.
All jars are added in lib. There are few local jars and I'm adding them directly under EAR file. I've 2 local jars with a different name but contains the same package say abc.jar and xyz.jar
When I deploy this file on server I get following error:
"{\"WFLYCTL0080: Failed services\" => {\"jboss.mbean.service.publish:service=StreamReceiverStartup.start\" => \"org.jboss.msc.service.StartException in service jboss.mbean.service.publish:service=StreamReceiverStartup.start: WFLYSAR0001: Failed to execute legacy service start() method
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NoClassDefFoundError: <package_name>/<class_file>
Caused by: java.lang.ClassNotFoundException: <class_file> from [Module \\\"deployment.<ear_file_name>.ear.<jar_name>.jar:main\\\" from Service Module Loader]\"}}"
It's trying to detect from abc.jar instead xyz.jar which contains .
How to resolve this conflict? I tried removing one of the jar files. It results in the same exception but for a different class file, so I cannot discard any of these jars.
This is fixed by removing jars from application.xml

classloading in Wildfly 9

I am deploying my application to Wildfly 9 and I am getting a strange error that resembles class loading problems. The same war file deploys successfully to Tomcat so I am guessing Wildfly is bundling com.google classes and somehow it is interfering with the bundled libraries in the war file.
First, the error looks like this:
Caused by: java.lang.IllegalAccessError: tried to access method com.google.common.collect.MapMaker.makeComputingMap(Lcom/google/common/base/Function;)Ljava/util/concurrent/ConcurrentMap; from class com.google.inject.internal.Annotations$AnnotationChecker
at com.google.inject.internal.Annotations$AnnotationChecker.<init>(Annotations.java:104)
at com.google.inject.internal.Annotations.<clinit>(Annotations.java:122)
at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:362)
at com.google.inject.Key.strategyFor(Key.java:354)
at com.google.inject.Key.get(Key.java:222)
at org.eclipse.sisu.wire.ParameterKeys.<clinit>(ParameterKeys.java:28)
at org.eclipse.sisu.wire.DependencyAnalyzer.<init>(DependencyAnalyzer.java:92)
at org.eclipse.sisu.wire.ElementAnalyzer.<init>(ElementAnalyzer.java:87)
at org.eclipse.sisu.wire.WireModule.configure(WireModule.java:74)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:94)
at com.google.inject.Guice.createInjector(Guice.java:71)
at com.google.inject.Guice.createInjector(Guice.java:61)
and I have both guava-16.0.1.jar and sisu-guice-3.1.0-no_aop.jar inside my war file's lib folder.
so I basically need to solve this issue, whether it is a class loading issue or not.

Groovy class not found exception by thirdparty java class during run-app

We are using a third party tool (Snowbound docViewer) which is expected to execute application's class file which is passed to the tool as a parameter. But this tool is not able to find the class passed to it only when we do run-app, it works with the war file. However same works when war is deployed to standalone tomcat server. May be class loader used to execute tool is different from our application.
I am trying to load the class like
File file = Locator.getClassSource(DocumentContentHandler)
def classLoader = BootStrap.class.classLoader.rootLoader
String path = Locator.fileToURL(file)
classLoader.addURL(new URL(path +'com/mycompany/snowbound/DocumentContentHandler.class'));
Url value generated is :
"file:/Users/amitjain/projects/mycompany/target/classes/com/mycompany/snowbound/DocumentContentHandler.class"
The exception I get is
java.lang.ClassNotFoundException: com.mycompany.snowbound.DocumentContentHandler
at org.codehaus.groovy.tools.RootLoader.findClass(RootLoader.java:175)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:147)
at org.codehaus.groovy.grails.cli.support.GrailsRootLoader.loadClass(GrailsRootLoader.java:51)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.snowbound.clientcontentserver.RetrievalProcessorConfigurator.initContentClass(RetrievalProcessorConfigurator.java:977)
Even when I do the following I get class not found exception.
Class.forName('com.mycompany.snowbound.DocumentContentHandler', true, BootStrap.class.classLoader.parent)
What can I do here? Thanks,

Categories

Resources