繁体   English   中英

如何使用Maven包插件在OSGi包中包含一罐依赖项?

[英]How to include a jar of dependency in an OSGi bundle using maven bundle plugin?

我有一个符合OSGi的bundle(jar),我想在其中添加一个依赖项的jar。 我要添加的dependecy是数据库驱动程序的。 我正在使用的Karaf容器的lib文件夹中没有该jar,因此无法手动将其添加到其中。 我只能访问可在其中部署捆绑包的deploy文件夹。 我正在使用maven包插件来打包我的包。 因此,我想知道是否有一种方法可以在我的捆绑软件中添加依赖项jar。 当前,我通过在7zip中打开捆绑包来手动将jar添加到捆绑包中,然后通过将其复制到jar中来添加jar,它可以正常工作。 我尝试使用<embed-dependency>标记,但是这样做之后,该捆绑包将无法部署。 什么办法吗?

以下是我要添加到捆绑软件中的pom.xml中的依赖项:

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.3.158</version>
    </dependency>

以下是pom.xml的build标记:

<build>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Export-Package>
                        com.ct.service.userService.*,
                        org.h2.*
                    </Export-Package>
                    <Import-Package>
                        *,
                        org.codehaus.jackson.jaxrs
                    </Import-Package>
                    <Embed-Dependency>h2</Embed-Dependency>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

尝试部署它时出现以下错误:

ERROR: Bundle com.ge.dsp.userService [205] Error starting file:D:Karaf/deploy/userService-0.0.1-SNAPSHOT.jar (org.osgi.framework.BundleException: Unresolved constraint in bundle com.ge.dsp.userService [205]: Unable to resolve 205.2: missing requirement [205.2] osgi.wiring.package; (osgi.wiring.package=org.apache.lucene.analysis))

org.osgi.framework.BundleException: Unresolved constraint in bundle com.ct.service.userService [205]: Unable to resolve 205.2: missing requirement [205.2] osgi.wiring.package; (osgi.wiring.package=org.apache.lucene.analysis)
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3826)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:1868)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:295)
    at java.lang.Thread.run(Thread.java:662)

看来我需要将h2-1.3.158.jar连同我的捆绑h2-1.3.158.jar一起部署,并在pom.xml添加一些编辑,如下所示:

<build>
<defaultGoal>install</defaultGoal>
<plugins>
    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
            <instructions>
                <Export-Package>
                    com.ct.service.userService.*,
                    <!--org.h2.*    No need to export these dependency -->
                </Export-Package>
                <Import-Package>
                    *,
                    org.codehaus.jackson.jaxrs,
                    org.h2               <!-- Needed to import the dependencies. -->
                </Import-Package>
                <!--<Embed-Dependency>h2</Embed-Dependency> No need of embedding -->
            </instructions>
        </configuration>
    </plugin>
</plugins>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM