How can i start OSGI framework from a plugin

If i try to start a bundle like this from simple class in the main method everything works fine:

FrameworkFactory fFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next(); //line 1
Framework framework = fFactory.newFramework(config);
..
context = framework.getBundleContext();
bundle = context.installBundle(myBundle);
bundle.start();


But if i do the same thing when the first file is opened, it dosn't work.

import org.osgi.framework.launch.FrameworkFactory;

public class MyEditor implements FileEditor, FileEditorManagerListener {
        private final VirtualFile file;
        private final Project project;

    static {
        FrameworkFactory frameworkFactory = ServiceLoader.load(FrameworkFactory.class).iterator().next(); // line 44
          ......
    }

I get this error:

  ERROR - com.intellij.ide.IdeEventQueue - Error during dispatching of java.awt.event.MouseEvent[MOUSE_RELEASED,(120,238),absolute(186,238),button=1,modifiers=Button1,clickCount=2] on frame0
java.util.ServiceConfigurationError: org.osgi.framework.launch.FrameworkFactory: Provider org.eclipse.osgi.launch.EquinoxFactory not a subtype
     at java.util.ServiceLoader.fail(ServiceLoader.java:231)
     at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
     at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:369)
     at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
     at myPackage.MyEditor.(MyEditor.java:44)
)


---
Original message URL: http://devnet.jetbrains.net/message/5504724#5504724

Please sign in to leave a comment.