Eclipse plugin bundle stuck in Starting state

eclipse-plugin, java, osgi

Solution

The following doesn't address the fact that the OSGi console reports the plugin to be `STARTING`, but it is an approach by which I got my plugin to start right after Eclipse started up.

As Chris Gerken points out in a comment, the startup code is only run when you try to use one of the plugin extensions.

Using the `org.eclipse.ui.startup` extension you can register a plugin that wants to be activated on startup. It is possible to set this up by using the manifest editor.

- Add `org.eclipse.ui` as a dependency in the "Dependencies" tab.

- In the "Extensions" tab add the Startup extension (`org.eclipse.ui.startup`).

- Underneath "Extension Element Details" provide a class which implements `org.eclipse.ui.IStartup`.

TaskManager.java

public class TaskManager implements IStartup
{
    @Override
    public void earlyStartup()
    {
        // This will get called when Eclipse is started,
        // after the GUI has been initialized.
    }
}

Problem

I used Eclipse to create a new plug-in project which created a default `Activator` for me. When debugging (running as Eclipse Application) I noticed the `start()` and `stop()` methods of this activator weren't called. Following the guide on what to do when your bundle isn't visible in Eclipse I stumbled upon the following results. - Using the `ss` command, I can see my bundle listed. - The status of my bundle is 'Starting' The bundle is in the process of starting. A bundle is in the `STARTING` state when its `start` method is active. A bundle must be in this state when the bundle's `BundleActivator.start(BundleContext)` is called. If the `BundleActivator.start` method completes without exception, then the bundle has successfully started and must move to the `ACTIVE` state. A breakpoint placed on the first line in the `start` method doesn't get hit. Neither does `System.out.println` show up in the console. What could cause the `start` method not getting called, and thus the state being stuck in `STARTING`?

Original source