簡體   English   中英

Karaf / Maven - 無法解決:缺少要求 osgi.wiring.package

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

我無法在 Karaf(版本 3.0.1)中啟動捆綁包。

該捆綁包是使用 maven 構建的,它導入gson

我根據需要在 maven 中包含了 gson:

<dependency>
     <groupId>com.google.code.gson</groupId>
     <artifactId>gson</artifactId>
     <version>2.3.1</version>
</dependency>

構建順利。 但是,在部署捆綁包時,我收到了來自 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]

未安裝捆綁包。

MANIFEST.MF中的Import-Package以:

Import-Package: com.google.gson;version="[2.3,3)"

我試圖改變它:

Import-Package: com.google.code.gson;version="[2.3,3)"

但它給了我一個類似的錯誤:

missing requirement [121.13] osgi.wiring.package; (&(osgi.wiring.package=com.google.code.gson)

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>

Google GSON 的MANIFEST.MF (我構建捆綁包時 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

我也試過

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

現在依賴項已嵌入,但 Karaf 無法啟動捆綁包。

我相信你在這里有兩個選擇。

如果您的MANIFEST.MF中有Import-Package: com.google.gson;version="[2.3,3)" ,這意味着您希望從已部署的包中導入某些包,而不是從嵌入式 jar 中導入。 在這種情況下,您應該首先部署gson-2.3.1.jar包(將此文件復制到部署文件夾),然后部署您的包。

如果您想將 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>

我有同樣的問題:

“無法解決blah-blah:缺少要求blah-blah osgi.wiring.package;(osgi.wiring.package=blah-blah)未解決的要求:[blah-blah] osgi.wiring.package;(osgi.wiring.package =胡說八道)]。

我在src/main/java中有一個激活器類。 當我在 Java 中再創建一個包並將激活器放在這里時,問題就解決了。 結果是src/main/java/oneMorePackage/MyActivator

標簽如下所示:

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

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

我遇到了同樣的問題:

org.osgi.service.resolver.ResolutionException:無法解析根:缺少需求 [root] osgi.identity; ...... [引起:無法解析 com.mycompany.somemodule/1.0.0.SNAPSHOT:缺少要求

並且解決了更改有問題的捆綁包的pom.xml (例如com.mycompany.somemodule/pom.xml ):

            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <configuration>
                <instructions>
                    <Export-Package>
                        com.mycompany.module.entity,
                        com.mycompany.somemodule.entity.v1,
                        com.mycompany.somemodule.entity.v2,
                        com.mycompany.somemodule.util
                    </Export-Package>
                    <Private-Package>
                        com.mycompany.somemodule,
                        com.mycompany.somemodule.translator
                    </Private-Package>
                    <Bundle-Name>Some Module</Bundle-Name>
                    <Bundle-SymbolicName>${project.name}</Bundle-SymbolicName>
                    <Bundle-Version>${project.version}</Bundle-Version>
                </instructions>

最初,問題是我只公開了這些包的一個子集:

               ...
               <Export-Package>
                    com.mycompany.somemodule.entity.v2
                </Export-Package>
                <Private-Package>
                </Private-Package>
                ...

我有這種錯誤。 這意味着 Karaf 沒有找到“依賴包”。

首先安裝依賴包,然后安裝你的包。

例如:

osgi:install mvn:com.yourCompany.corePackage.subPackage/yourDependencyBundle/1.0.0-SNAPSHOT

然后

osgi:install mvn:com.yourCompany.corePackage.subPackage/yourBundle/1.0.0-SNAPSHOT

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM