maven构建OSGi的问题包括依赖关系

qqi*_*ihq 9 osgi maven apache-felix

我目前正在开始使用OSGi,iPOJO和iPOJO Annotations,并尝试构建一个在Felix中部署的简单组件.不幸的是,我遇到了各种问题,这些问题花了我几个小时才解决,或者在浪费时间之后我甚至无法解决,如下所示:

我想使用我们使用Maven构建的OSGi包中的现有库.图书馆目前不是"OSGI-ified",我们不打算在中期内这样做.因此,我希望使用...包含此库及其所有依赖项.

<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
Run Code Online (Sandbox Code Playgroud)

我现在拥有的是OSGi组件的以下pom.xml文件:

<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>foo</groupId>
    <artifactId>samplecomponent</artifactId>
    <packaging>bundle</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArguments>
                        <encoding>UTF-8</encoding>
                    </compilerArguments>
                    <showDeprecation>true</showDeprecation>
                    <verbose>true</verbose>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <version>2.3.6</version>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                        <Embed-Dependency>*</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                        <Embed-Directory>lib</Embed-Directory>
                        <Export-Package>*</Export-Package>
                        <_exportcontents>*</_exportcontents>
                    </instructions>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-ipojo-plugin</artifactId>
                <version>1.6.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>ipojo-bundle</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.felix</groupId>
            <artifactId>org.apache.felix.ipojo.annotations</artifactId>
            <version>1.8.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>foo</groupId>
            <artifactId>mylibrary</artifactId>
            <version>1.2.3</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project>
Run Code Online (Sandbox Code Playgroud)

bundle jar文件构建没有任何问题,但是当在Apache Felix上部署和启动bundle时,我收到以下错误:

g! install file:/…/samplecomponent-0.0.1-SNAPSHOT.jar 
Bundle ID: 8
g! start 8
org.osgi.framework.BundleException: Unresolved constraint in bundle samplecomponent [8]: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package; (osgi.wiring.package=com.sun.jdmk.comm)
Run Code Online (Sandbox Code Playgroud)

我已将日志级别设置为最高详细程度,不幸的是没有更多信息.当我删除mylibrary时,捆绑启动没有问题.

任何建议赞赏!

Ang*_*jpt 10

显然,库使用com.sun.jdmk.comm,不从框架包中公开.如果您确实需要,可以查看此问题,或者通过添加附加说明将其从导入中排除,

<Import-Package>!com.sun.jdmk.comm, *</Import-Package>
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,这通常是一个很好的指针.但是,添加排除后,会弹出更多未解决的依赖项.我现在做的是将依赖项设置为"可选":`<Import-Package>*; resolution:= optional </ Import-Package>`现在我按预期工作了:) (3认同)