是否可以在具有不同ID的Eclipse插件中使用相同的包和类名? [英] Is it possible to use the same package and class name in Eclipse plugins with different ID?

查看:82
本文介绍了是否可以在具有不同ID的Eclipse插件中使用相同的包和类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建插件的克隆。我将更改插件ID以同时加载它们,但是我应该更改类的名称吗? Eclipse可以为每个插件使用不同的类路径,还是只从单个堆中的束中加载所有类?

I want to create a "clone" of the plug-in. I'm going to change the plug-in ID to load them simultaneously but should I change the names of the classes? Can Eclipse use a different class path for each plug-in or it just loads all classes from the bundles in the single heap?

推荐答案

这是否起作用取决于您在问题中未指定的因素,因此,我将为您提供Eclipse中类加载的工作原理的背景,您可以决定。

Whether or not this will work depends on factors you haven't specified in your question, so I will give you the background of how class loading works in Eclipse and you can decide.

Eclipse在顶级OSGi上运行。每个Eclipse插件都是一个OSGi捆绑包。每个捆绑软件都有自己的类加载器。该类加载器查看捆绑软件中包含的类以及捆绑软件依赖项中的类。捆绑包有两种方法来指定依赖项。两种方法都通过捆绑软件的MANIFEST.MF文件中的条目起作用。一种方法是使用Require-Bundle构造依赖于整个其他束。使用此方法,捆绑软件将查看其依赖项通过Export-Package导出的所有软件包。第二种方法是使用Import-Package。使用此方法,捆绑包将定位这样的包,任何捆绑包都将通过Export-Package导出。您还可以在生产者端对包和软件包进行版本控制,并在依赖项端对版本进行约束。

Eclipse runs on top OSGi. Each Eclipse plugin is an OSGi bundle. Each bundle has its own classloader. This classloader sees the classes contained in the bundle as well as classes from bundle's dependencies. There are two ways for a bundle to specify a dependency. Both methods work via entries in bundle's MANIFEST.MF file. One method is to use Require-Bundle construct to depend on a whole other bundle. Using this method, the bundle will see all packages that its dependency exports via Export-Package. The second method is to use Import-Package. Using this method, the bundle will locate such a package that any bundle exports via Export-Package. You can also version bundles and packages on the producer end and constrain versions on dependency end.

因此,掌握了这些知识之后,您需要问自己以下问题...

So, armed with this knowledge, you need to ask yourself these questions...


  1. 是您要克隆的捆绑包,通过Export-Package导出任何软件包。如果不是,那么您会没事的。

  1. Is the bundle that you are cloning exporting any packages via Export-Package. If it doesn't, then you will be fine.

当前有哪些捆绑包指定了您的原始捆绑包,并将通过Require-Bundle指定克隆?您要避免的情况是,单个捆绑包在Require-Bundle中同时指定了Bundle.Original和Bundle.Clone。如果需要这种安排,则必须重命名克隆的软件包。

What bundles currently specify your original bundle and will specify the clone via Require-Bundle? What you trying to avoid is a situation where a single bundle specifies both Bundle.Original and Bundle.Clone in Require-Bundle. If such arrangement is necessary, you will have to rename the cloned packages.

最后要检查的是,是否有任何捆绑包在您的任何捆绑包上使用Import-Package出口包装。如果是这样,您将需要对原始版本的软件包进行版本控制,并进行不同的克隆。这在Export-Package指令中发生。您还需要在Import-Package指令中仔细指定版本约束,以使其与原始版本或克隆版本匹配。未能版本包和约束导入将导致在运行时找到哪个版本的行为似乎是随机的。同样,如果单个下游捆绑包需要同时导入原始和克隆的软件包,则需要重命名克隆的软件包。

The final thing to check is whether any bundle uses Import-Package on any of your export packages. If it does, you will need to version packages in original and clone differently. This happens in Export-Package directive. You will also need to carefully specify version constrains in the Import-Package directives so that it matches the version of the original or the clone. Failing to version packages and constrain imports will result in seemingly random behavior as to which version is found at runtime. Again, if a single downstream bundle needs to import both original and cloned packages, you will need to rename the cloned packages.

这篇关于是否可以在具有不同ID的Eclipse插件中使用相同的包和类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆