卡拉夫/ Maven - 无法解决:缺少要求osgi.wiring.package [英] Karaf / Maven - Unable to resolve: missing requirement osgi.wiring.package
问题描述
该软件包使用maven构建,它导入gson 。
我在maven中包含gson as required:
<依赖项>
< groupId> com.google.code.gson< / groupId>
< artifactId> gson< / artifactId>
< version> 2.3.1< / version>
< /依赖关系>
构建进行得很顺利。但是,在部署捆绑软件时,我收到Karaf发出的这个警告:
2015-05-27 12:45:07,371 |警告| 49-19-bin / deploy | fileinstall | 11 - org.apache.felix.fileinstall - 3.2.8 |启动bundle时出错:file:/Users/user/Documents/tools/MyBundle-1.0.0-SNAPSHOT.jar
org.osgi.framework.BundleException:捆绑包MyBundle中的未解析约束[121]:无法解析121.13 :缺少要求[121.13] osgi.wiring.package; (&(osgi.wiring.package = com.google.gson)(version> = 2.3.0)(!(version> = 3.0.0)))
at org.apache.felix.framework.Felix .resolveBundleRevision(Felix.java:3974)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)[org .apache.felix.framework-4.2.1.jar:]
在org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1。 jar:]
在org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1263)[11:org.apache.felix.fileinstall:3.2.8]
at org。 apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1235)[11:org.apache.felix.fileinstall:3.2.8]
位于org.apache.felix.fileinstall.internal.DirectoryWatcher。 startAllBundles(DirectoryWatcher.java:1224)[11:org.apache.felix.fileinstall:3.2.8]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:519)[11 :org.apache.felix.fileinstall:3.2.8]
a t org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:308)[11:org.apache.felix.fileinstall:3.2.8]
未安装捆绑包。
Import-Package $ c
MANIFEST.MF
开始于:
Import-包:com.google.gson; version =[2.3,3)
我试图更改它与:
导入包:com.google.code.gson; version =[2.3,3)
但它给了我一个类似的错误:
缺少需求[121.13] osgi.wiring.package; (&(osgi.wiring.package = com.google.code.gson)
pom.xml :
<?xml version =1.0encoding = UTF-8?>
< 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> groupid< / groupId>
< ; artifactId> artifactid< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
< / parent>
< groupId> groupid< / groupId> ;
< artifactId> MyBundle< / artifactId>
< version> 1.0.0-SNAPSHOT< / version>
< packaging>包< / packaging>
< name> MyBundle< / name>
< description> MyBundle< / description>
< proper关系>
< skipTests>真< / skipTests>
< / properties>
<依赖关系>
...
< dependency>
< groupId> org.apache.felix< / groupId>
< artifactId> org.apache.felix.http.jetty< / artifactId>
< /依赖关系>
< dependency>
< groupId> org.json< / groupId>
< artifactId> com.springsource.org.json< / artifactId>
< /依赖关系>
< dependency>
< groupId> org.apache.servicemix.bundles< / groupId>
< artifactId> org.apache.servicemix.bundles.commons-httpclient< / artifactId>
< scope> test< / scope>
< /依赖关系>
< dependency>
< groupId> org.postgresql< / groupId>
< artifactId> postgresql< / artifactId>
< version> 9.4-1201-jdbc41< / version>
< /依赖关系>
< dependency>
< groupId> com.google.code.gson< / groupId>
< artifactId> gson< / artifactId>
< version> 2.3.1< / version>
< /依赖关系>
< dependency>
< groupId> commons-codec< / groupId>
< artifactId> commons-codec< / artifactId>
< version> 1.10< / version>
< /依赖关系>
< /依赖关系>
< build>
< plugins>
< plugin>
< groupId> org.apache.felix< / groupId>
< artifactId> maven-bundle-plugin< / artifactId>
< extensions> true< / extensions>
<配置>
<指令>
< Bundle-SymbolicName> $ {project.artifactId}< / Bundle-SymbolicName>
< / instructions>
< / configuration>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-surefire-plugin< / artifactId>
<配置>
< skipTests> $ {skipTests}< / skipTests>
< / configuration>
< / plugin>
< / plugins>
< / build>
< / project>
Google GSON的 MANIFEST.MF
当我构建包时,maven会下载这个版本):
pre $ code Manifest-Version 1.0
Export-Package:com .google.gson; version = 2.3.1,com.google.gson.annotat
ion; version = 2.3.1,com.google.gson.reflect; version = 2.3.1,com.google
.gson.stream;版本= 2.3.1,com.google.gson.internal;版本= 2.3.1,c
om.google.gson.internal.bind;版本= 2.3.1
Bundle-ClassPath:。
Built-By:inder
Bundle-Name:Gson
创建者:Apache Maven 3.2.1
Bundle-RequiredExecutionEnvironment:J2SE-1.5,JavaSE-1.6,JavaSE-1.7 ,
JavaSE-1.8
Bundle-Vendor:Google Gson Project
Bundle-ContactAddress:http://code.google.com/p/google-gson/
Build-Jdk :1.6.0_65
Bundle-Version:2.3.1
Bundle-ManifestVersion:2
Bundle-Description:Google Gson library
Bundle-SymbolicName:com.google.gson
Archiver-Version:Plexus Archiver
我也尝试过使用
< build>
< plugins>
< plugin>
< groupId> org.apache.felix< / groupId>
< artifactId> maven-bundle-plugin< / artifactId>
< extensions> true< / extensions>
<配置>
<指令>
< Bundle-SymbolicName> $ {project.artifactId}< / Bundle-SymbolicName>
< Import-Package> *;分辨率:=可选< / Import-Package>
< Embed-Dependency> *< / Embed-Dependency>
< Embed-Transitive> true< / Embed-Transitive>
< / instructions>
< / configuration>
< / plugin>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-surefire-plugin< / artifactId>
<配置>
< skipTests> $ {skipTests}< / skipTests>
< / configuration>
< / plugin>
< / plugins>
< / build>
现在依赖关系已被嵌入,但Karaf无法启动捆绑包。
<
如果您有 Import-在你的
,这意味着你想要一些包要从已部署的包中导入,而不能从嵌入式jar导入。在这种情况下,您应该首先部署 MANIFEST.MF
中包:com.google.gson; version =[2.3,3] gson-2.3.1.jar
捆绑包(将此文件复制到deploy文件夹),然后部署捆绑包。
如果要将gson库作为简单的非OSGi jar依赖项嵌入,也可以这样做,但是必须从 Import-包
:
< plugin>
< groupId> org.apache.felix< / groupId>
< artifactId> maven-bundle-plugin< / artifactId>
< extensions> true< / extensions>
<配置>
<指令>
< Bundle-SymbolicName> $ {project.artifactId}< / Bundle-SymbolicName>
< Import-Package>!com.google.gson,*< / Import-Package>
< Embed-Dependency> gson< / Embed-Dependency>
< / instructions>
< / configuration>
< / plugin>
I am unable to start a bundle in Karaf (version 3.0.1).
The bundle is built using maven and it imports gson.
I included gson in maven as required:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
The build goes fine. However, when deploying the bundle I receive this Warning from Karaf:
2015-05-27 12:45:07,371 | WARN | 49-19-bin/deploy | fileinstall | 11 - org.apache.felix.fileinstall - 3.2.8 | Error while starting bundle: file:/Users/user/Documents/tools/MyBundle-1.0.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Unresolved constraint in bundle MyBundle [121]: Unable to resolve 121.13: missing requirement [121.13] osgi.wiring.package; (&(osgi.wiring.package=com.google.gson)(version>=2.3.0)(!(version>=3.0.0)))
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1263)[11:org.apache.felix.fileinstall:3.2.8]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1235)[11:org.apache.felix.fileinstall:3.2.8]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1224)[11:org.apache.felix.fileinstall:3.2.8]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:519)[11:org.apache.felix.fileinstall:3.2.8]
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:308)[11:org.apache.felix.fileinstall:3.2.8]
The bundle is not installed.
The Import-Package
in the MANIFEST.MF
begins with:
Import-Package: com.google.gson;version="[2.3,3)"
I tried to change it with:
Import-Package: com.google.code.gson;version="[2.3,3)"
But it gives me a similar error:
missing requirement [121.13] osgi.wiring.package; (&(osgi.wiring.package=com.google.code.gson)
The pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>groupid</groupId>
<artifactId>artifactid</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>groupid</groupId>
<artifactId>MyBundle</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>MyBundle</name>
<description>MyBundle</description>
<properties>
<skipTests>true</skipTests>
</properties>
<dependencies>
...
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.http.jetty</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>com.springsource.org.json</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.commons-httpclient</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4-1201-jdbc41</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</project>
The MANIFEST.MF
of Google GSON (the version maven downloads when I build the bundle) is:
Manifest-Version: 1.0
Export-Package: com.google.gson;version=2.3.1, com.google.gson.annotat
ions;version=2.3.1, com.google.gson.reflect;version=2.3.1, com.google
.gson.stream;version=2.3.1, com.google.gson.internal;version=2.3.1, c
om.google.gson.internal.bind;version=2.3.1
Bundle-ClassPath: .
Built-By: inder
Bundle-Name: Gson
Created-By: Apache Maven 3.2.1
Bundle-RequiredExecutionEnvironment: J2SE-1.5, JavaSE-1.6, JavaSE-1.7,
JavaSE-1.8
Bundle-Vendor: Google Gson Project
Bundle-ContactAddress: http://code.google.com/p/google-gson/
Build-Jdk: 1.6.0_65
Bundle-Version: 2.3.1
Bundle-ManifestVersion: 2
Bundle-Description: Google Gson library
Bundle-SymbolicName: com.google.gson
Archiver-Version: Plexus Archiver
I also tried with
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>*;resolution:=optional</Import-Package>
<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skipTests}</skipTests>
</configuration>
</plugin>
</plugins>
</build>
Now the dependencies are embedded but Karaf cannot start the bundle.
I believe you have two options here.
If you have Import-Package: com.google.gson;version="[2.3,3)"
in your MANIFEST.MF
, this means that you want some package to be imported from a deployed bundle, not from an embedded jar. In this case, you should first deploy gson-2.3.1.jar
bundle (copy this file to the deploy folder), and then deploy your bundle.
If you want to embed the gson library as a simple non-OSGi jar dependency, this also can be done, but then you have to exclude its packages from Import-Package
:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Import-Package>!com.google.gson,*</Import-Package>
<Embed-Dependency>gson</Embed-Dependency>
</instructions>
</configuration>
</plugin>
这篇关于卡拉夫/ Maven - 无法解决:缺少要求osgi.wiring.package的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!