【问题标题】:Detecting running Equinox IApplication ID检测正在运行的 Equinox IApplication ID
【发布时间】:2018-11-17 14:30:55
【问题描述】:

我有带有 GUI (JavaFX) 的 RCP E4 应用程序。它还包含几个没有 GUI 的 IApplication 实例。问题是,有一些自动运行的 DS 服务,我想检测从这些 DS 服务中启动的应用程序(IApplication/产品 ID)。这可能吗?我能得到什么信息?

【问题讨论】:

    标签: osgi eclipse-rcp equinox efxclipse


    【解决方案1】:

    IApplicationContext 包含许多方法来告诉您它所谓的“品牌应用”。

    getBrandingApplication 为您提供正在运行的应用程序的 ID(例如,对于 e4,总是 org.eclipse.e4.ui.workbench.swt.E4Application`)。

    getBrandingId 是产品 ID。

    getBrandingName 是为产品指定的名称。

    在 e4 应用程序中,您只需注入 IApplicationContextIApplication 应用程序被赋予 cpntext 作为 start 方法的参数。也可以通过搜索 OSGi 服务找到:

    IApplicationContext getApplicationContext(BundleContext context) {
        Collection<ServiceReference<IApplicationContext>> references;
        try {
            references = context.getServiceReferences(IApplicationContext.class, "(eclipse.application.type=main.thread)"); 
        } catch (InvalidSyntaxException e) {
            return null;
        }
        if (references == null || references.isEmpty())
            return null;
        // assumes the application context is available as a service
        ServiceReference<IApplicationContext> firstRef = references.iterator().next();
        IApplicationContext result = context.getService(firstRef);
        if (result != null) {
            context.ungetService(firstRef);
            return result;
        }
        return null;
    }
    

    (以上代码改编自org.eclipse.core.internal.runtimeInternalPlatform

    【讨论】:

    • 它给了我产品 id 和名称,但是当 IApplication 执行时 getBrandingId() 返回 null
    • 如果通过指定 `-application xx' 启动它不是产品的一部分,因此没有产品 ID。
    猜你喜欢
    • 2019-06-21
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    相关资源
    最近更新 更多