簡體   English   中英

嘗試以編程方式在 Equinox 中安裝包時出現 nullPointerException

[英]nullPointerException when trying to programmatically install a bundle in Equinox

我正在嘗試做一個簡單的演示,在其中啟動 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 );
    }
}
}

我很確定 start() 和 init() 應該是相反的順序。

// Initialize the framework
framework.init( );

// Start the framework
framework.start( );

我也遇到了這個問題,我發現使用 apache felix 而不是 equinox 作為 OSGi 框架時不會出現此錯誤。

這並不是一個真正的解釋,但切換到 felix 可能是一種可能的解決方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM