【问题标题】:How to configure LogService for embedded Apache Felix?如何为嵌入式 Apache Felix 配置 LogService?
【发布时间】:2016-02-13 19:25:28
【问题描述】:

我正在尝试在我的应用程序中嵌入 Apache Felix。它工作得很好,除非我的一个捆绑包开始取决于osg.osgi.service.log

这是我如何启动嵌入式 Felix:

    Map<String, Object> config = new HashMap<>();
    config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.service.log,my.custom.package");
    config.put(FelixConstants.LOG_LEVEL_PROP, "3");

    felix = new Felix(config);

    try {
        felix.start();
    } catch (BundleException e) {
        //...
    }

    felix.getBundleContext().installBundle("file:my-bundle.jar").start();

这是我的捆绑清单的样子:

    Export-Package: my.custom.bundle;uses:="my.custom.package,org.osgi.framework,org.osgi.service.log";version="0.0.1"
    Import-Package: my.custom.package,org.osgi.framework;version="[1.5,2)",org.osgi.service.log;version="[1.3,2)"

安装包时,我收到以下异常日志:

    org.osgi.framework.BundleException: Unable to resolve my.custom.bundle [1](R 1.0): missing requirement [my.custom.bundle [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.service.log (version>=1.3.0)(!(version>=2.0.0))) Unresolved requirements: [[my.custom.bundle [1](R 1.0)] osgi.wiring.package; (&(osgi.wiring.package=org.osgi.service.log)(version>=1.3.0)(!(version>=2.0.0)))]
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4111)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2117)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1371)
        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
        at java.lang.Thread.run(Thread.java:745)

我尝试导入将org.apache.felix.log添加到FRAMEWORK_SYSTEMPACKAGES_EXTRA,或者将org.apache.felix.log.Activator添加到SYSTEMBUNDLE_ACTIVATORS_PROP没有效果。

【问题讨论】:

    标签: java logging osgi apache-felix osgi-bundle


    【解决方案1】:

    最好将包含 org.osgi.service.log 的包安装到嵌入式 OSGi 容器中。

    如果你真的想从外部类加载器中使用它,你应该在 org.osgi.framework.system.packages.extra 配置中指定包的版本。

    config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.service.log;version="x.x.x",my.custom.package");
    

    其中 x.x.x 应替换为您在类路径中的包版本。应大于或等于 1.3.0 且小于 2.0.0。

    我可以想象,只有在容器应用程序(嵌入 OSGi 容器)中注册实现此接口的服务时,您才希望从外部类加载器中使用此包。

    【讨论】:

    • 感谢它的工作。我不确定安装包和从外部类加载器使用它之间的区别,但我现在正在安装它,它工作得很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    • 2016-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多