Search code examples
javaeclipsepluginsworkspace

"Workbench has not been created yet" error in eclipse plugin programming


With my eclipse plugin launching, I got Root exception:java.lang.IllegalStateException: Workbench has not been created yet. error.

And it seems to cause side effect to make some bundle exception error. I don't think my code uses egit module.

org.osgi.framework.BundleException: Exception in org.eclipse.egit.ui.Activator.start() of bundle org.eclipse.egit.ui.
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:734)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
    at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
    at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)

How can I remove this error? This is the code that accesses the workspace. I found this article - Debugging a failed Eclipse launch saying that it's race condition, but I'm not sure why I have race condition, and if so, how to remove it.

public void renameClassRefactor() throws CoreException {
    // get the project information with ResourcesPlugin
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    // 1. The name of the project in the workspace

    System.out.println(ResourcesPlugin.getWorkspace().toString());
    java.io.File workspaceDirectory = root.getLocation().toFile();
    System.out.println(workspaceDirectory.toString());

Solution

  • Referring to this site, I could add -clean parameter in Run Configuration to remove the error message.

    enter image description here