java - Apache Felix OSGI 安装依赖项

标签 java maven osgi slf4j apache-felix

OSGI bundle 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>

一切都捆绑并安装正常。当我尝试启动该 bundle 时,我被告知我缺少安装的 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)))]

希望我越来越接近......

谢谢!

最佳答案

您有两个错误需要解决。第一个是“碎片包无法启动”。错误消息告诉您需要了解的一切。 slf4j 实现包是片段,并且您无法启动片段。所以不要启动它们!

您还没有指定如何运行 OSGi 框架,但在某个地方您必须有一些代码来迭代所有已安装的 bundle 并在每个 bundle 上调用 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...这是您正在构建的 bundle 吗?你的代码中真的使用了Ehcache吗?如果是这样,您显然需要安装 Ehcache 包。如果您确实安装了 Ehcache,那么它可能是错误的版本;您的 bundle 需要版本 2.10.0 至 3.0.0(但不包括 3.0.0)。

关于java - Apache Felix OSGI 安装依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31451567/

相关文章:

java - 如何修复无法降低 ContextWrapper 继承方法的可见性错误?

java - 如何使用 Hibernate 定义友谊关系?

java - MutliModule 和 EAR 之间的区别

mysql - 带有多个定界符的 sql-maven-plugin

Spring 框架下载为 OSGi 包

java - Amdatu:如何使 ExceptionMapper (@Provider) 工作?

java - 访问者模式中元素的访问级别

java.lang.UnsupportedClassVersionError : Bad version number in . 类文件?

java - "java.lang.ClassNotFoundException: org.codehaus.jackson.map.ObjectMapper"在 Eclipse 火星

javascript - 无法在 Karaf OSGi 中加载 ScriptEngineManager 和 ScriptEngine(找不到 Nashorn)