Closed Chaho12 closed 1 month ago
You would need to inject every single linked class. That is not normally recommended. What are you trying to do?
You would need to inject every single linked class. That is not normally recommended. What are you trying to do?
Yeah that was the issue. I had to add every single linked class, which is seemly impossible as Jackson is too big.
What I wanted to do was, create a separate class file(esSender.java) that sends data to elastic search. Within esSender, we use Jackson to create message string to send to ES.
create an abstract class with a public static field of itself. set that field with a subclass that is not injected. only use jvm types in your abstract class.
only use jvm types in your abstract class.
Hmm.. I don't quite understand this part. is there any links that you can share what you mean by jvm types?
types the the java package.
create an abstract class with a public static field of itself. set that field with a subclass that is not injected. only use jvm types in your abstract class.
@raphw, do you mind describing this design pattern in more detail? I'm trying to solve the same problem.
You would create a class like this:
public abstract class Dispatcher {
public static Dispatcher dispatcher;
public abstract void doDispatch();
}
Once on the boot loader, you can implement this dispatcher from your own class loader and set an instance as the field value. You then callback the method via this field.
@raphw thanks for the quick response. How would I access my own class loader from the Agent to create the Dispatcher implementation?
This seems incorrect:
Dispatcher.dispatcher = (Dispatcher) Class.forName("agent.DispatcherImpl", false, customClassLoader) .newInstance();
This is what I receive when I do the above:
java.lang.ClassCastException: class agent.DispatcherImpl cannot be cast to class agent.Dispatcher (agent.DispatcherImpl is in unnamed module of loader 'app'; agent.Dispatcher is in unnamed module of loader 'bootstrap')
Nevermind - I see what you mean now. Just gotta play with the classloaders. Thanks!
Nevermind - I see what you mean now. Just gotta play with the classloaders. Thanks!
Could you share it? How do I inject into the dispatcher? I tried to implement my own classloader Dispatcher, but when setting it up, I got an error saying their class loaders are different.
HI, I have issue with class loading where it cannot find certain libraries.
Where esSender.java:24 has error at
private static final ObjectMapper jackson = new ObjectMapper();
.Any ideas or comments would be helpful on finding out why it saids
NoClassDefFoundError