Java Karaf / Maven - 无法解决:缺少要求 osgi.wiring.package

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30480508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 09:42:22  来源:igfitidea点击:

Karaf / Maven - Unable to resolve: missing requirement osgi.wiring.package

javamavengsonapache-karaf

提问by gc5

I am unable to start a bundle in Karaf (version 3.0.1).

我无法在 Karaf(版本 3.0.1)中启动一个包。

The bundle is built using maven and it imports gson.

该包是使用 maven 构建的,并导入gson

I included gson in maven as required:

我根据需要在 Maven 中包含了 gson:

<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:

构建顺利。但是,在部署捆绑包时,我收到来自 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-Packagein the MANIFEST.MFbegins with:

Import-PackageMANIFEST.MF开头:

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:

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.MFof Google GSON (the version maven downloads when I build the bundle) is:

MANIFEST.MF谷歌GSON(版本Maven同时下载时,我建的软件包)是:

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.

现在依赖项已嵌入,但 Karaf 无法启动包。

采纳答案by Sergei Petunin

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.jarbundle (copy this file to the deploy folder), and then deploy your bundle.

如果您在Import-Package: com.google.gson;version="[2.3,3)"MANIFEST.MF,这意味着您希望从部署的包中导入一些包,而不是从嵌入式 jar 中导入。在这种情况下,您应该首先部署gson-2.3.1.jar包(将此文件复制到部署文件夹),然后部署您的包。

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:

如果您想将 gson 库嵌入为一个简单的非 OSGi jar 依赖项,也可以这样做,但是您必须从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>

回答by Милана Нургалиева

I've got the same problem:

我有同样的问题:

"Unable to resolve blah-blah: missing requirement blah-blah osgi.wiring.package; (osgi.wiring.package=blah-blah) Unresolved requirements: [blah-blah] osgi.wiring.package; (osgi.wiring.package=blah-blah)].

“无法解决 blah-blah:缺少需求 blah-blah osgi.wiring.package; (osgi.wiring.package=blah-blah) 未解决的需求:[blah-blah] osgi.wiring.package; (osgi.wiring.package = blah-blah)]。

I had an activator class inside src/main/java. The problem was solved, when I created one more package inside Java and put my activator here. The result is src/main/java/oneMorePackage/MyActivator

我里面有一个激活器类src/main/java。当我在 Java 中再创建一个包并将我的激活器放在这里时,问题就解决了。结果是src/main/java/oneMorePackage/MyActivator

The tags looks like this:

标签如下所示:

<Bundle-Activator>
       oneMorePackage.MyActivator
</Bundle-Activator>

<Private-Package>
      oneMorePackage
</Private-Package>