如何使用 Maven 捆绑包插件在 OSGi 捆绑包中包含依赖项 jar?

2023-12-31

我有一个兼容 OSGi 的包(jar),我想在其中添加一个依赖项的 jar。我想添加的依赖项是数据库驱动程序。该 jar 不存在于我正在使用的 Karaf 容器的 lib 文件夹中,并且无法手动将其添加到那里。我只能访问部署文件夹,我可以在其中部署我的包。我正在使用 Maven 捆绑插件来打包我的捆绑包。所以,我想知道是否有办法在我的包中添加依赖项 jar。目前,我通过在 7zip 中打开捆绑包并通过将其复制到 jar 中来添加 jar 来手动将 jar 添加到捆绑包中,并且工作正常。我尝试使用<embed-dependency>标签,但完成此操作后,捆绑包不会被部署。有没有any怎么办呢?

以下是其中的依赖关系pom.xml我想将其添加到捆绑包中:

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

以下是构建标签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.*
                    </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与我的捆绑包一起并添加在中进行一些编辑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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 Maven 捆绑包插件在 OSGi 捆绑包中包含依赖项 jar? 的相关文章

随机推荐