When you need to select "Create Activator ..." when creating a new Eclipse plug-in project

There are many Eclipse RCP tutorials that start with the obvious first step: "Create a new plugin project ..."

It seems that approx. 70% of them indicate the check "Generate an activator, a Java class that controls the life cycle of a plug-in . " Others who specifically say do not verify that they are switching.

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

It’s not clear to me what the activator class generates for you when you need it and when not.

In order to be an important option that you get every time you create a new plug-in project (apparently it is installed by default), this option is not very well explained anywhere I found.

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

+7
java eclipse eclipse-plugin eclipse-rcp
source share
4 answers

From Eclipse itself (context-sensitive help for the dialog), this suggests this, which is of little use.

"Activator is a Java class that controls the life cycle of a plug-in. This is only necessary if you need to do the work when you start or shut down your plugin. "

When this option is enabled, the Activator.java class is automatically generated for your new project.

So it seems that if (being a little newbie) you have no idea why or what extra work you should do when starting / stopping plugins, you can safely leave this OFF. Only one .java file is displayed in the source folder of the project.

+4
source share

One way to find out is to look at the generated class. It turns out that this is a subclass of AbstractUIPlugin . Browse JavaDoc, it provides services such as preference management, image registry, etc. If you need it, you can use it. This is a subclass of Plugin that makes sense.

In addition, it implements the BundleActivator , which has a useful JavaDoc. This gives you stubs for start () and stop (), which allows you to include your own code here. It also generates the static convenience method getDefault (), which the activator gives you. And all this to him.

+4
source share

If you really want to find out, check out the OSGi specification ; release 4 is the current version. Starting with Eclipse 3, each plugin is an OSGi package. The beam activator is notified when the beam starts and stops, which usually happens when Eclipse starts and stops. You can also install listeners that are notified of the launch of other packages (such as plugins) or the registration of OSGi services.

For example, I use a listener to start certain operations after my package has completed its launch; otherwise, I may run into class loader issues. You may also need an activator to store the BundleContext, which allows you to load classes and gives you access to the name and version of the package.

+1
source share
-one
source share

All Articles