|Classloading: Unable to load class of a dependent plugin from a java project [message #667206]
||Wed, 27 April 2011 08:29
Registered: April 2011
Below is the description and the structure of my project and plug-ins code base.|
1. A java project named 'SampleProject' having package 'com.sample.action'.
2. A plug-in project named 'SamplePluginA' having reference of above java project's jar file which is set as Bundle-ClassPath also.
3. A plug-in project named 'SamplePluginB' having reference of the exported package 'sample.action' from 'SamplePluginA' for 'SampleProject'.
Now, at runtime execution of the plug-in 'SamplePluginB', the class 'sample.action.A' of 'SampleProject' is invoked which tries to load the class 'B' located under the 'SamplePluginB'. While loading this class, it throws the ClassCastException because the class loaders for both the classes differs. Whereas, if 'sample.action.A' tries to load a class located under the 'SampleProject' then it succeeds.
The configuration in the respective MANIFEST.MF is done as follows:
1. MANIFEST.MF of SamplePluginA has the entry for SampleProject.jar:
2. build.properties of SamplePluginA has the entry:
bin.includes = lib/SampleProject.jar
jars.extra.classpath = lib/SampleProject.jar
3. MANIFEST.MF of SamplePluginB has the entry:
The Class B is the implementation of an interface that belongs to SampleProject and a Decorator is implemented which tried to load implementor classes of this interface which are registered within the chain. This chain is build by the builder class located under the SamplePluginB.
I have tried to load the Class B from the Class located under the SampleProject by the ClassLoader object obtained from the Activator class of the SamplePluginB. This approach works fine because the class will always be loaded from its class loader. But, i need a way where i dont need to pass a ClassLoader to my core class.
I would also like to know whether am i missing any configuration in the plugin.xml or have i made mistake by creating SamplePluginB as a plugin and i would have created it as a fragment?
Thanks & Regards,
Powered by FUDForum
. Page generated in 0.11978 seconds