Question

I have really tricky problem. I have kinda container which can run custom JAR with the method which has a class ComponentContext as a parameter. After loading I want to invoke this method with the reflection but there is a problem - I must use the same class loader (JCL in this case) to create ComponentContext. See the code:

JclObjectFactory factory = JclObjectFactory.getInstance();
Object context = factory.create(jcl, "org.hive.lib.component.ComponentContextImpl");

Method setConfigDirMethod = context.getClass().getMethod("initialize", File.class, File.class);
setConfigDirMethod.invoke(context, configDir, workspace);

Method method = instance.getClass().getMethod("initialize", context.getClass());
method.invoke(instance, context);

And when I'm trying to pass context created in container like this

ComponentContextImpl c = new ComponentContext();

It fails with java.lang.IllegalArgumentException because of another classloader.

It means that my container depends on class from the JAR, it drives me crazy. It there a way to pass my own ComponentContext (not instantiated from the JAR) to the method initialize?

PS - JAR was assembled with assembly:single

Was it helpful?

Solution

Solved as marking shared library as provided

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top