nullPointerException when trying to programmatically install a bundle in Equinox

旧城冷巷雨未停 提交于 2019-12-07 09:44:30

问题


I'm trying to do a simple demo where I start the Equinox Framework and then load a tutorial bundle that was created (via the tutorial). I keep getting NullPointerExceptions here is the stack trace...

Exception in thread "main" java.lang.NullPointerException
    at org.eclipse.osgi.internal.baseadaptor.BaseStorageHook.mapLocationToURLConnection(BaseStorageHook.java:372)
    at org.eclipse.osgi.baseadaptor.BaseAdaptor.mapLocationToURLConnection(BaseAdaptor.java:185)
    at org.eclipse.osgi.framework.internal.core.Framework$1.run(Framework.java:835)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.eclipse.osgi.framework.internal.core.Framework.installWorker(Framework.java:888)
    at org.eclipse.osgi.framework.internal.core.Framework.installBundle(Framework.java:832)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.installBundle(BundleContextImpl.java:167)
    at org.eclipse.osgi.framework.internal.core.BundleContextImpl.installBundle(BundleContextImpl.java:161)
    at com.mydemo.bootstrap.Bootstrap.main(Bootstrap.java:35)

here is the code ...

public class Bootstrap
{

public static void main( String[ ] args ) throws BundleException , InterruptedException , MalformedURLException
{

    // Load the framwork factory
    ServiceLoader loader = ServiceLoader.load( FrameworkFactory.class );
    FrameworkFactory factory = ( FrameworkFactory ) loader.iterator( ).next( );

    // Create a new instance of the framework
    Framework framework = factory.newFramework( null );

    try
    {
        // Start the framework
        framework.start( );
        framework.init( );

        BundleContext bc = framework.getBundleContext( );
        bc.installBundle( "file:/c:/Users/kirk/Desktop/plugins/org.equinoxosgi.toast.client.emergency_1.0.0.201106290845.jar" );
    }
    finally
    {
        // Stop the framework
        framework.stop( );

        // Wait for the framework to stop completely
        framework.waitForStop( 3000 );
    }
}
}

回答1:


I ran into this problem as well, and I found that you don't get this error when using apache felix instead of equinox as the OSGi framework.

It's not really an explanation, but switching to felix might be a possible workaround.




回答2:


I am pretty sure that start() and init() should be in the opposite order.

// Initialize the framework
framework.init( );

// Start the framework
framework.start( );


来源:https://stackoverflow.com/questions/6522285/nullpointerexception-when-trying-to-programmatically-install-a-bundle-in-equinox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!