覆盖Maven-Bundle-Plugin中的需求能力 [英] Override Require-Capability in Maven-Bundle-Plugin

查看:96
本文介绍了覆盖Maven-Bundle-Plugin中的需求能力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题类似于此问题,但是我正在使用Maven捆绑插件来达到相同的最终结果.

My question is similar to this one but I am using the Maven bundle plugin to achieve the same end result.

我正在构建一个包含persistence.xml文件的捆绑软件,并且发现maven-bundle-plugin在清单中自动生成以下标头:

I am building a bundle that contains a persistence.xml file and I have found that the maven-bundle-plugin automatically generates the following headers in the manifest:

Require-Capability:osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
Require-Capability: osgi.extender;osgi.extender=aries.jpa, 
Require-Capability: osgi.service;effective:=active;objectClass=javax.sql.DataSource;filter:="(osgi.jndi.service.name=jdbc/test)"

这本身不是问题,但是我正在使用Karaf,并且我想在自己的一个功能中部署此包和其他捆绑软件以及Karaf功能.当我这样做时,它会失败,因为即使我指定了要同时安装的openjpa功能,OSGi也无法满足功能osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl的要求.我发现可以通过将effective:=active更改为resolution:=optional

This in itself is not a problem however I am using Karaf and I want to deploy this and other bundles and Karaf features in one single feature of my own. When I do this it fails because the OSGi is unable to fulfil the capability osgi.service;effective:=active;objectClass=javax.persistence.spi.PersistenceProvider;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl even though I specify the openjpa feature to be installed at the same time. I have discovered that I can get around this issue by changing effective:=active to resolution:=optional

要构建我的捆绑包,我尝试了以下Maven插件配置:

To build my bundle I've tried the following Maven plugin configuration:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>3.3.0</version>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Export-Package>com.example
            </Export-Package>
            <Include-Resource>
                        META-INF/persistence.xml=${project.build.directory}/classes/META-INF/persistence.xml,
                        {maven-resources}
            </Include-Resource>
            <Meta-Persistence>META-INF/persistence.xml</Meta-Persistence>
            <Require-Capability>
                        osgi.service;resolution:=optional;objectClass=javax.persistence.spi.PersistenceProvider;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl,
                        osgi.extender;resolution:=optional;osgi.extender=aries.jpa,
                        osgi.service;resolution:=optional;objectClass=javax.sql.DataSource;filter:="(osgi.jndi.service.name=jdbc/test)"
            </Require-Capability>
        </instructions>
    </configuration>
</plugin>

但是我遇到了与上面链接的问题相同的问题,即清单中的需求重复.

However I get the same issue as in the linked question above i.e. duplicated requirements in the manifest.

我还从上述问题的链接中看到对bnd进行了更改(bnd问题#1364),但这似乎仅适用于注释?有没有一种方法可以配置Maven插件来防止需求重复?

I also see from a link on the above question that a change was made to bnd (bnd issue #1364) but this appears to only work for annotations? Is there a way to configure the Maven plugin to prevent duplicated requirements?

我的示例代码可在GitHub(karaf_features分支)上找到: https://github.com/jtkb/jpatest/tree/feature/karaf_features

My example code is available here at GitHub (karaf_features branch): https://github.com/jtkb/jpatest/tree/feature/karaf_features

它由3个模块组成,但只有2个与该问题有关,分别为simplesimple-datasource

It consists of 3 modules but only 2 are of interest for this issue, simple and simple-datasource

simple是持久性单元",并且包含persistence.xml.也是在其中生成尴尬"(尚有实际要求)<Require-Capability>标头的包.

simple is the 'persistence unit' and contains the persistence.xml. It is also the bundle in which the 'awkward' (yet real requirements) <Require-Capability> headers are generated.

simple-datasource将数据源提供给持久性单元,并包含一个Karaf功能,用于安装simplesimple-datasource捆绑软件和所有必需的第三方捆绑软件(通过Karaf功能).功能XML包含:

simple-datasource provides the datasource to the persistence unit and contains a Karaf feature to install simple, simple-datasource bundles and all the required 3rd party bundles (via Karaf features). The feature XML contains:

<feature name="simple-datasource" description="simple-datasource" version="1.0.0.SNAPSHOT">
    <feature version="4.1.1">jdbc</feature>
    <feature version="2.6.0">jpa</feature>
    <feature version="2.4.1">openjpa</feature>
    <feature version="1.0.1">pax-jdbc-mariadb</feature>
    <bundle>mvn:com.javatechnics.jpa/simple-datasource/1.0.0-SNAPSHOT</bundle>
    <bundle>mvn:com.javatechnics.jpa/simple/1.0.0-SNAPSHOT</bundle>
</feature>

因此在Karaf中安装我的功能时出现此错误:

So installing my feature in Karaf I get this error:

执行命令时出错:无法解析root:缺少要求[root] osgi.identity; osgi.identity =简单数据源;类型= karaf.feature;版本="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]";过滤器:=(&(osgi.identity =简单数据源)(类型= karaf.feature)(版本> = 1.0.0.SNAPSHOT)(版本< = 1.0.0.SNAPSHOT))"

Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=simple-datasource; type=karaf.feature; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; filter:="(&(osgi.identity=simple-datasource)(type=karaf.feature)(version>=1.0.0.SNAPSHOT)(version<=1.0.0.SNAPSHOT))"

[原因:无法解析simple-datasource/1.0.0.SNAPSHOT:缺少要求[simple-datasource/1.0.0.SNAPSHOT] osgi.identity; osgi.identity = com.javatechnics.jpa.simple;类型= osgi.bundle;版本="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]";分辨率:=强制性

[caused by: Unable to resolve simple-datasource/1.0.0.SNAPSHOT: missing requirement [simple-datasource/1.0.0.SNAPSHOT] osgi.identity; osgi.identity=com.javatechnics.jpa.simple; type=osgi.bundle; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; resolution:=mandatory

[原因:无法解析com.javatechnics.jpa.simple/1.0.0.SNAPSHOT:缺少要求[com.javatechnics.jpa.simple/1.0.0.SNAPSHOT] osgi.service; objectClass = javax.persistence.spi.PersistenceProvider; javax.persistence.provider = org.apache.openjpa.persistence.PersistenceProviderImpl;有效:=有效]]

[caused by: Unable to resolve com.javatechnics.jpa.simple/1.0.0.SNAPSHOT: missing requirement [com.javatechnics.jpa.simple/1.0.0.SNAPSHOT] osgi.service; objectClass=javax.persistence.spi.PersistenceProvider; javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl; effective:=active]]

对我来说,这个错误几乎感觉像是一个循环参考问题,但我看不到如何解决.

The error to me almost feels like a circular reference issue but I cannot see how.

检查simple捆绑包的标题:

simple (59)
-----------
Bnd-LastModified = 1513115007378
Build-Jdk = 1.8.0_144
Built-By = kerry
Created-By = Apache Maven Bundle Plugin
Manifest-Version = 1.0
Meta-Persistence = META-INF/persistence.xml
Tool = Bnd-3.2.0.201605172007

Bundle-Blueprint = OSGI-INF/blueprint/blueprint.xml
Bundle-ManifestVersion = 2
Bundle-Name = simple
Bundle-SymbolicName = com.javatechnics.jpa.simple
Bundle-Version = 1.0.0.SNAPSHOT

Export-Service = 
com.javatechnics.jpa.dao.BookServiceDao;ServiceManager=Blueprint;name=
BookServiceDao
Provide-Capability = 
osgi.service;effective:=active;objectClass=javax.persistence.EntityManagerFactory;osgi.unit.name=test,
osgi.service;effective:=active;objectClass=org.apache.aries.jpa.template.JpaTemplate;osgi.unit.name=test,
osgi.service;effective:=active;objectClass=javax.persistence.EntityManager;osgi.unit.name=test,
osgi.service;effective:=active;objectClass=org.apache.aries.jpa.supplier.EmSupplier;osgi.unit.name=test
Require-Capability = 
osgi.service;effective:=active;javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl;objectClass=javax.persistence.spi.PersistenceProvider,
osgi.extender;osgi.extender=aries.jpa,
 osgi.service;effective:=active;filter:=(osgi.jndi.service.name=jdbc/test);objectClass=javax.sql.DataSource,
osgi.ee;filter:=(&(osgi.ee=JavaSE)(version=1.5))

Export-Package = 
com.javatechnics.jpa;uses:="com.javatechnics.jpa.dao,javax.persistence";version=1.0.0,
com.javatechnics.jpa.dao;uses:=com.javatechnics.jpa;version=1.0.0
Import-Package = 
com.javatechnics.jpa,
com.javatechnics.jpa.dao,
javax.persistence;version="[1.1,2)",
org.osgi.service.blueprint;version="[1.0.0,2.0.0)"

推荐答案

如果您知道一个捆绑包,我们称其为xyz,提供了PersistenceProvider服务,那么您可以编写一个附加的只需执行以下操作的捆绑包即可:

If you know that a bundle, let’s call it xyz, provides the PersistenceProvider service then you can write one additional bundle that simply does this:

Require-Bundle: xyz; bundle-version="[...)"
Provide-Capability: osgi.service;
    objectClass=javax.persistence.spi.PersistenceProvider;
    javax.persistence.provider=org.apache.openjpa.persistence.PersistenceProviderImpl;
    effective:=active

这实质上增强了捆绑软件xyz的功能,该功能可以解决捆绑软件中的需求,但以增加其他无用的捆绑软件为代价.

This essentially augments bundle xyz with a capability that will resolve the requirement in your bundle, at the cost of adding an otherwise useless bundle.

这仍然是一种解决方法,但是比从捆绑中删除实际需求要好.

This is still something of a workaround but is better than removing a real requirement from a bundle.

这篇关于覆盖Maven-Bundle-Plugin中的需求能力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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