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

发布于 2024-11-17 14:55:28 字数 1957 浏览 1 评论 0原文

我正在尝试做一个简单的演示,在其中启动 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 );
    }
}
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遇见了你 2024-11-24 14:55:28

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

// Initialize the framework
framework.init( );

// Start the framework
framework.start( );

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

// Initialize the framework
framework.init( );

// Start the framework
framework.start( );
绮烟 2024-11-24 14:55:28

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文