尝试在 2 个 Eclipse 插件之间传递类实例时抛出 LinkageError
我发现很多人都有类似的问题,但没有灵魂...基本上我有两个 Eclipse 插件,它们在类路径中都依赖于同一个 jar。
UI插件依赖于Driver插件(为其实现自定义ODA驱动程序和UI)。两者都依赖于一个包含我的其他一些类的 jar,称为plugin-dto.jar
当 UI 插件调用 Driver 插件中的类之一的方法时,该方法返回一个对象,该对象的类在插件中找到-dto jar 我收到错误:
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.java: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)
有什么想法如何解决这个问题吗?
提前致谢。
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.java: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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是两个不同插件中加载的类实例是不同的,即使它们来自同一个 jar。 Eclipse Plugin 类加载器正在执行它应该执行的操作。假设插件 A 和插件 B 都尝试访问类 Z 的同一个实例,则此问题的几个解决方案是:
创建一个通用插件,将其命名为 D,其中包含并导出 Z。更新插件 A 和B 不包含 Z 的 jar,而是从 D 加载 Z。
将 A 和 B 设置为使用“Buddy Classloading”,请参阅 http:// /wiki.eclipse.org/index.php/Context_Class_Loader_Enhancements
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