【问题标题】:nullPointerException when trying to programmatically install a bundle in Equinox尝试以编程方式在 Equinox 中安装包时出现 nullPointerException
【发布时间】:2011-09-25 05:21:01
【问题描述】:

我正在尝试做一个简单的演示,我在其中启动 Equinox 框架,然后加载创建的教程包(通过教程)。我不断收到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 );
    }
}
}

【问题讨论】:

    标签: eclipse osgi equinox


    【解决方案1】:

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

    // Initialize the framework
    framework.init( );
    
    // Start the framework
    framework.start( );
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2017-08-24
        • 1970-01-01
        • 1970-01-01
        • 2018-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-15
        • 1970-01-01
        相关资源
        最近更新 更多