Maven构建的OSGi的问题,包括依赖项 [英] Problems with maven built OSGi including dependencies

查看:104
本文介绍了Maven构建的OSGi的问题,包括依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前从OSGi,iPOJO和iPOJO批注开始,并试图构建一个简单的组件以部署在Felix中.不幸的是,我正在解决各种问题,这些问题花了我几个小时才能解决,或者甚至浪费了几个小时也无法解决,如下所示:

I'm currently starting with OSGi, iPOJO and iPOJO Annotations and trying to build a simple component to be deployed in Felix. Unfortunately, I'm stumbling over various problems which take me hours to solve or which I cannot even solve after wasting hours, like the following:

我想在我使用Maven构建的OSGi捆绑包中使用现有的库.该库当前不是"OSGI标准化的",并且我们不打算在中期这样做.因此,我想使用…:

I want to use an existing library in my OSGi bundle which we build using Maven. The library is currently not "OSGI-ified" and we are not planning to do so in the medium term. Because of that, I want to include this library and all of its dependencies in the bundle, using …:

<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>

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

What I have now, is the following pom.xml file for the OSGi component:

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

构建的捆绑包jar文件没有任何问题,但是在Apache Felix上部署和启动捆绑包时,出现以下错误:

The bundle jar file is built without any problems, but when deploying and starting the bundle on Apache Felix, I get the following error:

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)

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

I have set the log level to the highest verbosity, no more information unfortunately. When I remove mylibrary, the bundle is started without problems.

任何建议表示赞赏!

推荐答案

显然,该库使用的是com.sun.jdmk.comm,它没有从框架捆绑包中公开.您可以检查此问题如果您确实需要它,或者通过添加一条附加说明将其从导入中排除,

Apparently, the library uses com.sun.jdmk.comm, which is not exposed from the framework bundle. You can check this question if you really need it, or exclude it from the imports by putting in an additional instruction,

<Import-Package>!com.sun.jdmk.comm, *</Import-Package>

这篇关于Maven构建的OSGi的问题,包括依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆