OSGi os.wiring.package 在 Karaf 中启动捆绑包时出错



我正在潜入OSGi领域并构建了一个捆绑包,我正在尝试将其安装到Karaf中。我收到以下错误:

我想知道这是蓝图的工作方式,还是我不知何故没有正确导出/导入模块?

我正在使用蓝图,我有如下所示的 impl 蓝图:

IMPL 的蓝图文件

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cxf="http://cxf.apache.org/blueprint/core"
xmlns:jaxrs="http://cxf.apache.org/schemas/jaxrs.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://cxf.apache.org/blueprint/core ">
<cxf:bus id="greetingServiceBus">
<cxf:features>
<cxf:logging/>
</cxf:features>
</cxf:bus>
<bean id="welcomeImpl" class="welcomeimpl.WelcomeImpl"/>
<service ref="welcomeImpl" interface="welcome.WelcomeAPI"/>
<jaxrs:server address="/tester" id="tester">
<jaxrs:serviceBeans>
<ref component-id="welcomeImpl"/>
</jaxrs:serviceBeans>
</jaxrs:server>
</blueprint>

错误

Error executing command: Error executing command on bundles: Error starting bundle 119: Unable to resolve impl [119](R 119.0): missing requirement [impl [119](R 119.0)] osgi.wiring.package; (osgi.wiring.package=welcome) Unresolved requirements: [[impl [119](R 119.0)] osgi.wiring.package; (osgi.wiring.package=welcome)]

嘟.xml

<parent>
<artifactId>learning-osgi</artifactId>
<groupId>com.osgirest</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>bundle</packaging>
<artifactId>impl</artifactId>
<dependencies>
<dependency>
<groupId>com.osgirest</groupId>
<artifactId>welcome-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</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>
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>
javax.ws.rs*,
com.learning.welcomeimpl
</Export-Package>
<Import-Package>
*,
javax.ws.rs*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

API POM.xml

<parent>
<artifactId>learning-osgi</artifactId>
<groupId>com.osgirest</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>welcome-api</artifactId>
<packaging>bundle</packaging>
<name>welcome-api Bundle</name>
<description>api to welcome people into the application</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator/>
<Export-Package>
com.learning.welcome;version=${project.version}
</Export-Package>
<Import-Package>
*
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

目录结构

├── impl
│   ├── impl.iml
│   ├── pom.xml
│   ├── src
│   │   ├── main
│   │   │   ├── java
│   │   │   │   └── com
│   │   │   │       └── learning
│   │   │   │           └── welcomeimpl
│   │   │   │               └── WelcomeImpl.java
│   │   │   └── resources
│   │   │       └── OSGI-INF
│   │   │           └── blueprint
│   │   │               └── blueprint.xml
│   │   └── test
│   │       └── java
│   └── target
│       ├── classes
│       │   ├── META-INF
│       │   │   └── MANIFEST.MF
│       │   ├── OSGI-INF
│       │   │   └── blueprint
│       │   │       └── blueprint.xml
│       │   └── com
│       │       └── learning
│       │           └── welcomeimpl
│       │               └── WelcomeImpl.class
│       ├── generated-sources
│       │   └── annotations
│       ├── impl-1.0-SNAPSHOT.jar
│       └── maven-status
│           └── maven-compiler-plugin
│               ├── compile
│               │   └── default-compile
│               │       ├── createdFiles.lst
│               │       └── inputFiles.lst
│               └── testCompile
│                   └── default-testCompile
│                       └── inputFiles.lst
├── learningosgi.iml
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   └── resources
│   └── test
│       └── java
└── welcomeapi
├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── learning
│   │   │           └── welcome
│   │   │               └── WelcomeAPI.java
│   │   └── resources
│   └── test
│       └── java
├── target
│   ├── classes
│   │   ├── META-INF
│   │   │   └── MANIFEST.MF
│   │   └── com
│   │       └── learning
│   │           └── welcome
│   │               └── WelcomeAPI.class
│   ├── generated-sources
│   │   └── annotations
│   ├── maven-status
│   │   └── maven-compiler-plugin
│   │       ├── compile
│   │       │   └── default-compile
│   │       │       ├── createdFiles.lst
│   │       │       └── inputFiles.lst
│   │       └── testCompile
│   │           └── default-testCompile
│   │               └── inputFiles.lst
│   └── welcome-api-1.0-SNAPSHOT.jar
└── welcomeapi.iml

您的示例中存在一些问题,但让我们从您应该瞄准的目标开始。

在每个捆绑包中,您希望导出其他捆绑包应看到的包,并且要导入捆绑包所需的所有包。好消息是,maven-bundle-plugin在解决这些问题方面做得很好。

对于导入通常根本不定义任何东西。插件几乎总是做正确的事情。

对于导出,您的 API 包想要导出 com.learning.welcome,而 impl 包不需要导出任何内容。默认情况下,捆绑插件会导出除具有特殊名称(如 impl)的软件包之外的所有软件包。因此,默认值将再次做正确的事情。只需不要在两个捆绑包中定义任何导入和导出,这将是正确的。

最后一件事是蓝图。就像亚历山德罗解释的那样,你在那里使用了错误的软件包。maven 捆绑插件还会查看您的蓝图以找出导入。因此,它将导入不存在的包"welcome",当然不会由任何捆绑包导出。当我进行重构并且蓝图保持不变时,这个问题也对我打击很大。

您尝试与之交互的类不存在。

<bean id="welcomeImpl" class="welcomeimpl.WelcomeImpl"/>
<service ref="welcomeImpl" interface="welcome.WelcomeAPI"/>

应该是

<bean id="welcomeImpl" class="com.learning.welcomeimpl.WelcomeImpl"/>
<service ref="welcomeImpl" interface="com.learning.welcome.WelcomeAPI"/>

而且您没有导出正确的包:

<Export-Package>
com.learning.welcome;version=${project.version}
</Export-Package>

也在此处修复包或保留为*

最新更新