开发者

LinkageError thrown when attempting to pass instance of class between 2 eclipse plugins

I have found many people with simliar issues but no soultions...basically I have two eclipse plug-ins that both in ther class path rely on the same jar.

The UI plug-in replies on the Driver plug-in (implementing a custom ODA driver and UI for it). Both rely on a jar containing some other classes of mine and is called plugin-dto.jar

When the UI plug-in calls a method on one of the classes in the Driver plug-in that returns an object whose class is found in the plugin-dto jar I get the error:

java.lang.LinkageError: Class com/test/reporting/NrDsDriverProvider violates loader constraints
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:183)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.j开发者_开发问答ava:576)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:546)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:477)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:465)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:445)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:211)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:381)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:457)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Any ideas how I get around this issue?

Thanks in advance.


The problem is that instances of classes loaded in two different plugins are different, even if they came from the same jar. The Eclipse Plugin class loader is doing what it is supposed to. Assuming that Plugin A and Plugin B are both trying to access the same instance of class Z, a couple of solutions to this problem are:

  • Create a common plugin, call it D, that contains and exports Z. Update Plugins A and B to not include the jar for Z and instead load Z from D.

  • Set up A and B to use "Buddy Classloading", see http://wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜