尝试以编程方式在Equinox中安装捆绑包时出现nullPointerException

时间:2011-06-29 14:24:25

标签: eclipse osgi equinox

我正在尝试做一个简单的演示,我启动Equinox Framework,然后加载一个创建的教程包(通过教程)。我一直在NullPointerExceptions这里是堆栈跟踪...

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)

这是代码......

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 );
    }
}
}

2 个答案:

答案 0 :(得分:0)

我也遇到了这个问题,我发现当使用apache felix而不是equinox作为OSGi框架时,你不会遇到这个错误。

这不是一个真正的解释,但切换到felix可能是一种可能的解决方法。

答案 1 :(得分:0)

我很确定start()和init()应该是相反的顺序。

// Initialize the framework
framework.init( );

// Start the framework
framework.start( );