Wednesday, November 23, 2011

java.lang.IllegalStateException: "Workbench has not been created yet"

I’ve been working with OSGi for quite awhile and have faced a problem "Workbench has not been createt yet" issues. I was getting this error, When i was trying to run OSGI plugin from Eclipse and I guess many of you must have face this problem. So i am writing a little bit about how to resolve this issue so others don’t repeat the same mistakes.

From a good article on eclipsezone:

java.lang.IllegalStateException: Workbench has not been created yet

This usually comes when someone tries to run a Java application against an OSGi bundle with java -classpath .... . It really means that the workbench plug-in hasn't started yet, and so calls to getWorkbench() fail. This is essentially a race condition, and can be solved by either expressing an explicit dependency on that bundle or bumping up that bundle to a higher start level than the workbench. Generally not seen, but if it is, that's what's happening.

Now to set the bundle to a higher start level than the workbench.
Select your manifest.mf, right-click, select Run As-> Run Configuration. Create a OSGi Framework launch configuration. Deselect all bundles except your bundle. Change the default set level to higher level and Press then "Add Required bundles"
Run this configuration. This should give you the correct output.

If you still get the same error ,then you can do
1. Add the -clean to the program Arguments.i,e(Run Configuration->OSGI framework->Arguments ->program Arguments)
                                           OR (Recommended 1 if failed then try 2)
2. Delete the .metadata folder which is created by default in Eclipse Workspace but before that please take the backup..:)




Hope its gonna work for you guys too..Feel free to comment.



6 comments:

  1. i tried both options..but no change..still getting same error..

    ReplyDelete
  2. Hi,
    Could you tell me the exact step that you are doing?

    ReplyDelete
  3. you can select Run As-> Run Configuration->Settings,and select 'clear the configuration area before launching.

    ReplyDelete
    Replies
    1. Thanks for the update, I'll try and let you know... :)

      Delete
  4. I struggled a lot for **“Workbench has not been created yet”** the complete day.

    But I got **the solution by the following steps**.-

    1. Go to the **Run configuration** -> Remove all the target platform jars.
    2. Click on add required bundles.
    3. Check the org.apache.felix.gogo.runtime, org.apache.felix.gogo.shell, org.eclipse.eqinox.console, org.eclipse.osgi and your jar file.
    4. The last and important step. Go to **Setting-**> **check** the checkbox of **"Clear the configuratation area before launching**".
    5. Run the OSGi application now.
    6. Enjoy if it works for you as it worked for me.

    Thanks

    ReplyDelete
    Replies
    1. Thanks for updating me one more way to resolve above issue.

      Delete

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...