문제

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

도움이 되었습니까?

해결책

Solved as marking shared library as provided

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top