如何在运行时获取自定义 Eclipse 功能的版本号?
我想在其透视图的标题栏中显示我正在开发的自定义 Eclipse 功能的版本号。 有没有办法从运行时插件和/或工作台获取版本号?
I would like to display the version number of a custom Eclipse feature I am developing in the title bar of its perspective. Is there a way to obtain the version number from the runtime plugin and/or workbench?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
比如:
应该能解决问题。
请注意(来自此线程)它不能在任何地方使用在插件本身内:
this.getBundle()
在您的插件上调用super.start(BundleContext)
后才有效。因此,如果您在调用
super.start()
之前在构造函数中或start(BundleContext)
中使用this.getBundle()
,那么它将返回 null。如果失败,您可以在这里获得更完整的“版本” :
Something like:
should do the trick.
Note (from this thread) that it can not be used anywhere within the plugin itself:
this.getBundle()
is not valid until AFTERsuper.start(BundleContext)
has been called on your plugin.So if you are using
this.getBundle()
within your constructor or within yourstart(BundleContext)
before callingsuper.start()
then it will return null.If that fails, you have here a more complete "version":
我使用第一个选项:
I use the first option:
正如 @zvikico 上面所说,接受的答案不适用于功能,仅适用于插件(OSGi 捆绑包,功能不适用于)。 获取有关已安装功能的信息的方法是通过
org.eclipse.core.runtime.Platform.getBundleGroupProviders()
作为 此处描述。As @zvikico says above, the accepted answer does not work for Features, only Plug-ins (OSGi Bundles, which Features are not). The way to get info about installed features is via
org.eclipse.core.runtime.Platform.getBundleGroupProviders()
as described here.VonC 提供的用于检索主 Eclipse 版本号的版本,但不引用内部类(您应该避免这样做):
A version of what VonC provided to retrieve the primary Eclipse version number, but one that doesn't reference internal classes (which you should avoid doing):