Apache Felix OSGI 安装依赖

Apache Felix OSGI installing dependencies

开始

我已将 maven-bundle-plugin 恢复为使用默认设置。这是我当前的 pom:

<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.felix.test</groupId>
    <artifactId>com.felix.test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>bundle</packaging>

    <dependencies>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.scr.annotations</artifactId>
            <version>1.9.6</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient-osgi</artifactId>
            <version>4.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>2.10.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.felix</groupId>
                        <artifactId>maven-bundle-plugin</artifactId>
                        <version>2.5.4</version>
                        <type>maven-plugin</type>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.5.4</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

一切都捆绑并安装正常。当我尝试启动捆绑包时,我被告知我缺少我安装的 net.sf.ehcache。然后我丢失了我安装的 slf4j.api 。然后我错过了 slf4j.impl 并且我已经尝试从 https://jpm4j.org/#!/ 安装几乎所有 slf4j.impl 的可能性但是大多数(slf4j-simple-1.7.12.jarslf4j-log4j12-1.7.12.jar)报告回来:

org.osgi.framework.BundleException: Fragment bundles can not be started.

这是我当前来自 GoGo 的错误:

org.osgi.framework.BundleException: Unable to resolve com.felix.test [16](R 16.0): missing requirement [com.felix.test [16](R 16.0)] osgi.wiring.package; (&(osgi.wiring.package=net.sf.ehcache)(version>=2.10.0)(!(version>=3.0.0))) [caused by: Unable to resolve net.sf.ehcache [17](R 17.0): missing requirement [net.sf.ehcache [17](R 17.0)] osgi.wiring.package; (&(osgi.wiring.package=org.slf4j)(version>=1.7.0)(!(version>=2.0.0))) [caused by: Unable to resolve slf4j.api [23](R 23.0): missing requirement [slf4j.api [23](R 23.0)] osgi.wiring.package; (&(osgi.wiring.package=org.slf4j.impl)(version>=1.6.0))]] Unresolved requirements: [[com.felix.test [16](R 16.0)] osgi.wiring.package; (&(osgi.wiring.package=net.sf.ehcache)(version>=2.10.0)(!(version>=3.0.0)))]

希望我越来越近了...

谢谢!

您有两个错误需要解决。第一个是 "fragment bundles cannot be started"。错误消息会告诉您需要知道的一切。 slf4j 实现包是片段,不能启动片段。所以不要启动它们!

您没有指定您是如何 运行 您的 OSGi 框架,但是您必须在某个地方有一些代码迭代所有已安装的包并在每个包上调用 start() 方法。您需要修改您的代码以不对作为片段的包调用 start()。您可以通过以下方式判断任何捆绑包是否是片段:

(bundle.adapt(BundleRevision.class).getTypes() | BundleRevision.TYPE_FRAGMENT) > 0;

或:

bundle.getHeaders().get(Constants.FRAGMENT_HOST) != null;

第二个错误表明名为 com.felix.test 的包依赖于包 net.sf.ehcache。我从未听说过 com.felix.test...这是您正在构建的捆绑包吗?你真的在你的代码中使用 Ehcache 吗?如果是这样,您显然需要安装 Ehcache 包。如果你确实安装了 Ehcache,那么它可能是错误的版本;您的捆绑包需要 2.10.0 版,但不包括 3.0.0.