何时在创建新的Eclipse插件项目时选择“生成激活器...”

时间:2023-01-17 13:49:03

There are lots of Eclipse RCP tutorials that begin with the obvious first step: "Create a new plugin project..."

有很多Eclipse RCP教程以明显的第一步开始:“创建一个新的插件项目......”

It seems that approx. 70% of them specify checking the "Generate an activator, a Java class that controls the plug-in life cycle". The others specifically say don't check that toggle.

似乎约。其中70%指定检查“生成激活器,控制插件生命周期的Java类”。其他人特别说不要检查切换。

alt text http://img179.imageshack.us/img179/6710/newpluginoptions.png

替代文字http://img179.imageshack.us/img179/6710/newpluginoptions.png

Its not clear to me, what generating an activator class does for you, when you need one, and when you don't.

我不清楚,当你需要一个激活类时,为你做什么,当你不需要时,它会为你做什么。

For being a prominent option you get every time you create a new plugin project (it seems to be set on by default) this option isn't very well explained anywhere that I have found.

为了成为一个突出的选项,每次你创建一个新的插件项目(它似乎默认设置)时,这个选项在我找到的任何地方都没有得到很好的解释。

Any advice/rules of thumb on choosing this option when creating Eclipse plugin projects?

在创建Eclipse插件项目时选择此选项的任何建议/经验法则?

4 个解决方案

#1


4  

From Eclipse itself (context sensitive help for the dialog) it says this, which is marginally useful.

从Eclipse本身(对话框的上下文敏感帮助),它说,这是有用的。

"An activator is a Java class that controls the plug-in's life cycle. It is only needed if you require to do work upon the startup or shutdown of your plug-in."

“激活器是一个控制插件生命周期的Java类。只有在你需要在启动或关闭插件时才能工作。”

When turning this option ON, an Activator.java class is auto-generated for your new project.

打开此选项时,将为您的新项目自动生成Activator.java类。

So, it sounds like if (being somewhat a novice) you have no idea why or what additional work you have to do at plugin startup/shutdown, you can safely leave this OFF. Just one less .java file showing up in your project source folder.

所以,听起来好像(有点新手)你不知道为什么或者你在插件启动/关闭时需要做些什么额外的工作,你可以安全地将其关闭。只需少一个.java文件显示在项目源文件夹中。

#2


4  

One way to find out is to look at the generated class. Turns out that it is a subclass of AbstractUIPlugin. Check out the JavaDoc, it provides services like preference management, image registry and the like. If you need any of this, you may want to use it. It is a subclass of Plugin, which kind of makes sense.

找出的一种方法是查看生成的类。原来它是AbstractUIPlugin的子类。查看JavaDoc,它提供了首选项管理,图像注册表等服务。如果您需要这些,您可能想要使用它。它是Plugin的一个子类,这是有道理的。

Also, it implements BundleActivator, which has some useful JavaDoc. This provides you with stubs for start() and stop(), which allows you to hook your own code in here. It also generates a static convenience method getDefault(), which gives you the Activator. And that's all there is to it.

此外,它实现了BundleActivator,它有一些有用的JavaDoc。这为您提供了start()和stop()的存根,允许您在此处挂钩自己的代码。它还会生成一个静态便捷方法getDefault(),它为您提供Activator。这就是它的全部。

#3


1  

If you really want to know, take a look at the OSGi specification; release 4 is the current version. Since Eclipse 3, every plugin is an OSGi bundle. The bundle activator is notified when the bundle is started and stopped, which usually happens when Eclipse starts and shuts down. You can also install listeners that are notified when other bundles (i.e. plugins) are started or register OSGi services.

如果您真的想知道,请查看OSGi规范;版本4是当前版本。从Eclipse 3开始,每个插件都是一个OSGi包。捆绑包启动和停止时会通知捆绑激活器,这通常发生在Eclipse启动和关闭时。您还可以安装在启动其他捆绑包(即插件)时通知的侦听器或注册OSGi服务。

For example, I use a listener to start certain operations after my bundle has completed its startup; otherwise I may run into classloader issues. You may also need the activator to store the BundleContext, which lets you load classes and gives you access to the bundle's name and version.

例如,在bundle完成启动后,我使用一个监听器来启动某些操作;否则我可能会遇到类加载器问题。您可能还需要激活器来存储BundleContext,它允许您加载类并允许您访问软件包的名称和版本。

#4


-1  

Here's the closest thing to an explanation I've found:

这是我发现的最接近的解释:

http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg23445.html

#1


4  

From Eclipse itself (context sensitive help for the dialog) it says this, which is marginally useful.

从Eclipse本身(对话框的上下文敏感帮助),它说,这是有用的。

"An activator is a Java class that controls the plug-in's life cycle. It is only needed if you require to do work upon the startup or shutdown of your plug-in."

“激活器是一个控制插件生命周期的Java类。只有在你需要在启动或关闭插件时才能工作。”

When turning this option ON, an Activator.java class is auto-generated for your new project.

打开此选项时,将为您的新项目自动生成Activator.java类。

So, it sounds like if (being somewhat a novice) you have no idea why or what additional work you have to do at plugin startup/shutdown, you can safely leave this OFF. Just one less .java file showing up in your project source folder.

所以,听起来好像(有点新手)你不知道为什么或者你在插件启动/关闭时需要做些什么额外的工作,你可以安全地将其关闭。只需少一个.java文件显示在项目源文件夹中。

#2


4  

One way to find out is to look at the generated class. Turns out that it is a subclass of AbstractUIPlugin. Check out the JavaDoc, it provides services like preference management, image registry and the like. If you need any of this, you may want to use it. It is a subclass of Plugin, which kind of makes sense.

找出的一种方法是查看生成的类。原来它是AbstractUIPlugin的子类。查看JavaDoc,它提供了首选项管理,图像注册表等服务。如果您需要这些,您可能想要使用它。它是Plugin的一个子类,这是有道理的。

Also, it implements BundleActivator, which has some useful JavaDoc. This provides you with stubs for start() and stop(), which allows you to hook your own code in here. It also generates a static convenience method getDefault(), which gives you the Activator. And that's all there is to it.

此外,它实现了BundleActivator,它有一些有用的JavaDoc。这为您提供了start()和stop()的存根,允许您在此处挂钩自己的代码。它还会生成一个静态便捷方法getDefault(),它为您提供Activator。这就是它的全部。

#3


1  

If you really want to know, take a look at the OSGi specification; release 4 is the current version. Since Eclipse 3, every plugin is an OSGi bundle. The bundle activator is notified when the bundle is started and stopped, which usually happens when Eclipse starts and shuts down. You can also install listeners that are notified when other bundles (i.e. plugins) are started or register OSGi services.

如果您真的想知道,请查看OSGi规范;版本4是当前版本。从Eclipse 3开始,每个插件都是一个OSGi包。捆绑包启动和停止时会通知捆绑激活器,这通常发生在Eclipse启动和关闭时。您还可以安装在启动其他捆绑包(即插件)时通知的侦听器或注册OSGi服务。

For example, I use a listener to start certain operations after my bundle has completed its startup; otherwise I may run into classloader issues. You may also need the activator to store the BundleContext, which lets you load classes and gives you access to the bundle's name and version.

例如,在bundle完成启动后,我使用一个监听器来启动某些操作;否则我可能会遇到类加载器问题。您可能还需要激活器来存储BundleContext,它允许您加载类并允许您访问软件包的名称和版本。

#4


-1  

Here's the closest thing to an explanation I've found:

这是我发现的最接近的解释:

http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg23445.html