views:

87

answers:

3

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

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.

alt text

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?

A: 

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

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

Anon Support 2010
+3  A: 

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

"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."

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

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.

Anon Support 2010
But the question was 'when should I create an Activator', not 'how ...'.
FelixM
good point. removed the last section and put in a related question.is there a way to embed a link to other related questions?
Anon Support 2010
A: 

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.

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.

FelixM