束中未解决的约束

Unresolved constraint in bundle

当我尝试通过 Maven 将我的包部署到 OSGi 时,这显示为已安装状态。我的项目是多模块的,所以有两个包。我在 taglib bundle 中看到的是:

org.apache.felix.shell from org.apache.felix.shell (292)
org.apache.jackrabbit.api,version=[2.3,3) from org.apache.jackrabbit.jackrabbit-api (65)
org.apache.jackrabbit.api.jsr283.security -- Cannot be resolved
org.apache.jackrabbit.api.security,version=[2.3,3) from org.apache.jackrabbit.jackrabbit-api (65)
org.apache.jackrabbit.api.security.principal,version=[2.3,3) from org.apache.jackrabbit.jackrabbit-api (65)
org.apache.jackrabbit.api.security.user,version=[2.3,3) from org.apache.jackrabbit.jackrabbit-api (65)

查看日志后,我看到如下:

14.04.2017 17:23:03.330 *ERROR* [FelixDispatchQueue] com.abc.MyPrj-services FrameworkEvent ERROR (org.osgi.framework.BundleException: Unresolved constraint in bundle com.abc.MyPrj-services [290]: Unable to resolve 290.0: missing requirement [290.0] osgi.wiring.package; (osgi.wiring.package=org.apache.jackrabbit.api.jsr283.security)) org.osgi.framework.BundleException: Unresolved constraint in bundle com.abc.MyPrj-services [290]: Unable to resolve 290.0: missing requirement [290.0] osgi.wiring.package; (osgi.wiring.package=org.apache.jackrabbit.api.jsr283.security)
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3896)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:1938)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1261)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:298)
    at java.lang.Thread.run(Thread.java:745)

我在两个模块 taglib、services 中都添加了以下依赖项。

 <dependency>
            <groupId>org.apache.jackrabbit</groupId>
            <artifactId>jackrabbit-api</artifactId>
            <version>2.5.2</version>
            <scope>provided</scope>
        </dependency>

下面是taglib模块的pom:

<plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>
                            com.mypkg.gwms.ra.tags.*;version=${project.version}
                        </Export-Package>
                        <Import-Package>
                            com.adobe.granite.*,
                            com.day.*,
                            javax.*,
                            org.apache.commons.*,
                            org.apache.sling.*,
                            org.apache.tika.*,
                            org.osgi.*,
                            org.w3c.dom.*,
                            org.xml.sax.*,
                            org.slf4j.*,
                            org.apache.felix.shell.*,
                            org.apache.jackrabbit.*,
                        </Import-Package>
                        <Include-Resource>
                            META-INF/${project.artifactId}-${project.version}.tld=${project.build.outputDirectory}/META-INF/${project.artifactId}-${project.version}.tld,
                            {maven-resources},
                            {maven-dependencies}
                        </Include-Resource>
                        <Sling-Bundle-Resources>
                            /META-INF/tags
                        </Sling-Bundle-Resources>
                    </instructions>
                </configuration>
            </plugin>

谢谢,

错误提示您还需要安装提供包 org.apache.jackrabbit.api.jsr283.security.

的包

如果导出此包,您可以签入包的清单。

您应该安装一个包含 org.apache.jackrabbit.api.jsr283.security 包的包并将其导出到您的 osgi 容器。

我需要有 2 个相同 API 但版本不同的依赖项。最新的是在服务模块中使用。其他模块 taglib,正在寻找相同依赖项的旧版本来解析 org.apache.jackrabbit.api.jsr283.security

为了解决这个问题,我在 pom.xml 中添加了以下语句。

<Import-Package>
org.apache.jackrabbit.*;version=1.6.1 
</Import-Package>

只导入1.6.1版本。成功了。