我正在深入OSGi土地并构建了一个我正试图安装到Karaf
的软件包。我收到以下错误:
我想知道蓝图是否正常工作,或者我是不是正确地导出/导入模块?
我正在使用蓝图,我的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)]
<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>
<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
答案 0 :(得分:2)
你的例子中有一些问题,但我们从你应该瞄准的目标开始。
在每个捆绑包中,您要导出其他捆绑包应该看到的包,并且您要导入捆绑包所需的所有包。好消息是maven-bundle-plugin在搞清楚这些方面做得很好。
对于进口通常只是没有定义任何东西。该插件几乎总是做正确的事。
对于您的API捆绑包想要导出com.learning.welcome的导出,并且impl包不需要导出任何内容。默认情况下,bundle插件导出除具有impl之类特殊名称的包之外的所有包。因此,默认值也会做正确的事情。只是不要在两个包中定义任何导入和导出,这是正确的。
最后一件事是蓝图。就像亚历山德罗解释说你在那里使用了错误的包裹。 maven bundle插件还会查看您的蓝图以确定导入。所以它将导入非existant包“welcome”,当然不会被任何包导出。当我进行重构并且蓝图保持不变时,这个问题也给我带来了很大的影响。
答案 1 :(得分:0)
您尝试与之交互的课程不存在。
<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>
也可以在此处修复包裹,或保留为*