【问题标题】:OSGi Bundle not get resolved automaticallyOSGi Bundle 无法自动解析
【发布时间】:2014-04-04 09:04:49
【问题描述】:

我编写了一个简单的 OSGi 包,这里是源文件。当我将它安装在 Equinox OSGi 容器中时,它不会自动解决它。有人可以解释我在这里做错了什么吗??

package org.sample.api;

/**
* Created on 3/11/14.
*/
public interface Hello {

    void sayHello();
}

这是包的 pom.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>osgi</artifactId>
        <groupId>osgi</groupId>
        <version>1.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>sample-api</artifactId>
    <version>1.0</version>
    <packaging>bundle</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.5</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-Vendor>Sample Inc</Bundle-Vendor>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Export-Package>
                            org.sample.api*;version=1.0.0
                        </Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

清单.MF

Manifest-Version: 1
Bnd-LastModified: 1396602001251
Build-Jdk: 1.6.0_45
Built-By: Zeus
Bundle-ManifestVersion: 2
Bundle-Name: sample-api
Bundle-SymbolicName: sample-api
Bundle-Vendor: Sample Inc
Bundle-Version: 1.0.0
Created-By: Apache Maven Bundle Plugin
Export-Package: org.sample.api;version="1.0.0"
Tool: Bnd-1.43.0

这是包安装控制台输出

    Bundle id is 7
RegisteredServices   null
ServicesInUse        null
LoaderProxy          sample-api; bundle-version="1.0.0"
Fragments            null
ClassLoader          null
Version              1.0.0
LastModified         1396605985751
Headers               Bnd-LastModified = 1396602001251
 Build-Jdk = 1.6.0_45
 Built-By = Zeus
 Bundle-ManifestVersion = 2
 Bundle-Name = sample-api
 Bundle-SymbolicName = sample-api
 Bundle-Vendor = Sample Inc
 Bundle-Version = 1.0.0
 Created-By = Apache Maven Bundle Plugin
 Export-Package = org.sample.api;version="1.0.0"
 Manifest-Version = 1
 Tool = Bnd-1.43.0


BundleContext        null
BundleId             7
StartLevel           1
SymbolicName         sample-api
BundleData           sample-api_1.0.0
KeyHashCode          7
StateChanging        null
BundleDescription    sample-api_1.0.0
Framework            org.eclipse.osgi.framework.internal.core.Framework@65cb687f
ResolutionFailureException org.osgi.framework.BundleException: The bundle "sample-api_1.0.0 [7]" could not be resolved
Revisions            [sample-api_1.0.0]
Key                  7
ProtectionDomain     null
Location             file:/home/Zeus/idea-projects/osgi/sample-api/target/sample-api-1.0.jar
State                2
Bundle                   7|Installed  |    1|sample-api (1.0.0)

【问题讨论】:

    标签: java osgi equinox modularity


    【解决方案1】:

    请从 jar 中发布生成的 MANIFEST.MF。我看不出 pom 有什么问题。

    如果捆绑包没有被解析,那么它处于什么状态?安装了吗?一个可能的原因是捆绑包的某些传递依赖项在容器上不可用。

    P.S:您可能希望为 maven-bundle-plugin 使用最新版本 2.4.0。

    EDIT1 这是我得到的清单:

    清单版本:1.0
    Bnd-LastModified: 1396605817562
    构建-Jdk:1.7.0_45
    建造者: anshuman
    捆绑清单版本:2
    捆绑包名称:sample-api
    Bundle-SymbolicName:示例-api
    捆绑供应商:Sample Inc
    捆绑版本:1.0.0
    创建者:Apache Maven Bundle Plugin
    导出包:org.sample.api;version="1.0.0"
    工具:Bnd-2.1.0.20130426-122213

    EDIT2 我希望您在安装后能够刷新并启动捆绑包。
    刷新 7
    开始 7
    其中 7 是您的捆绑包 ID。

    【讨论】:

    • 添加了清单数据。它处于已安装状态。使用“diag”命令时,它说 no No unresolved constraints。
    • 不是必须的,但是要排错,可以加一个Bundle-Activator,看看是否调用了start。
    • 我尝试在我的机器上运行您的示例(我使用的是捆绑插件的 Karaf,2.4.0),它工作正常:87 |活跃 | 80 | 1.0.0 |示例-api
    • 我已经添加了安装控制台输出。我有一个“ResolutionFailureException org.osgi.framework.BundleException:无法解析捆绑包“sample-api_1.0.0 [7]””异常。
    【解决方案2】:

    看起来您的捆绑包中没有激活器,至少您给定的示例不包含激活器,并且生成的清单的输出不包含捆绑激活器部分。在这一点上,我会说您的捆绑包处于已解决状态,因为它不能处于活动状态。

    【讨论】:

      【解决方案3】:

      INSTALLED 状态不是错误条件。这只是意味着已经安装了bundle,这是真的。

      如果您确实看到实际的错误消息,请提供详细信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-07-04
        • 1970-01-01
        • 2012-04-04
        • 2012-12-06
        • 2017-05-12
        • 2012-10-11
        • 1970-01-01
        相关资源
        最近更新 更多