Java OSGi:缺少要求OSGi.willing.package
我写了一个包含5个模块的项目。我使用intellij IDEA和maven创建它们,然后向所有模块添加“OSGi”框架支持。我使用maven bundle插件来配置导出包和导入包。但当我运行它时,总会出现一个错误:Java OSGi:缺少要求OSGi.willing.package,java,maven,intellij-idea,osgi,Java,Maven,Intellij Idea,Osgi,我写了一个包含5个模块的项目。我使用intellij IDEA和maven创建它们,然后向所有模块添加“OSGi”框架支持。我使用maven bundle插件来配置导出包和导入包。但当我运行它时,总会出现一个错误: org.osgi.framework.BundleException: Unable to resolve org.gxkl.launcher [12] (R 12.0): missing requirement [org.gxkl.launcher [12](R 12.0)]
org.osgi.framework.BundleException: Unable to resolve org.gxkl.launcher [12] (R 12.0): missing requirement [org.gxkl.launcher [12](R 12.0)] osgi.wiring.package; (osgi.wiring.package=org.gxkl.server).
启动器模块包含Bundle Activator,org.gxkl.server包位于服务模块中。我使用类似的pom来配置模块,但只有服务模块出错。
launcher中的pom文件如下所示:
<?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">
<parent>
<artifactId>${parent.artifactId}</artifactId>
<groupId>${parent.groupId}</groupId>
<version>${parent.version}</version>
</parent>
<modelVersion>${model.version}</modelVersion>
<artifactId>launcher</artifactId>
<packaging>bundle</packaging>
<dependencies>
...
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>service</artifactId>
<version>${project.version}</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>org.gxkl.Starter</Bundle-Activator>
<Export-Package>
org.gxkl
</Export-Package>
<Import-Package>
<!--some packages in other modules. They work fine-->
...
org.gxkl.server <!--packge in service modules. It doesn't work fine-->
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<?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">
<parent>
<artifactId>${parent.artifactId}</artifactId>
<groupId>${parent.groupId}</groupId>
<version>${parent.version}</version>
</parent>
<modelVersion>${model.version}</modelVersion>
<artifactId>service</artifactId>
<packaging>bundle</packaging>
<description>...</description>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
org.gxkl.server,
...
</Export-Package>
<Import-Package>
...
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
${parent.artifactId}
${parent.groupId}
${parent.version}
${model.version}
发射装置
捆
...
${project.groupId}
服务
${project.version}
...
org.apache.maven.plugins
maven源插件
org.apache.maven.plugins
maven编译器插件
org.apache.felix
maven捆绑插件
真的
org.gxkl.Starter
org.gxkl
...
org.gxkl.server
正在使用的pom文件如下所示:
<?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">
<parent>
<artifactId>${parent.artifactId}</artifactId>
<groupId>${parent.groupId}</groupId>
<version>${parent.version}</version>
</parent>
<modelVersion>${model.version}</modelVersion>
<artifactId>launcher</artifactId>
<packaging>bundle</packaging>
<dependencies>
...
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>service</artifactId>
<version>${project.version}</version>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>org.gxkl.Starter</Bundle-Activator>
<Export-Package>
org.gxkl
</Export-Package>
<Import-Package>
<!--some packages in other modules. They work fine-->
...
org.gxkl.server <!--packge in service modules. It doesn't work fine-->
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<?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">
<parent>
<artifactId>${parent.artifactId}</artifactId>
<groupId>${parent.groupId}</groupId>
<version>${parent.version}</version>
</parent>
<modelVersion>${model.version}</modelVersion>
<artifactId>service</artifactId>
<packaging>bundle</packaging>
<description>...</description>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>
org.gxkl.server,
...
</Export-Package>
<Import-Package>
...
</Import-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
${parent.artifactId}
${parent.groupId}
${parent.version}
${model.version}
服务
捆
...
...
org.apache.maven.plugins
maven源插件
org.apache.maven.plugins
maven编译器插件
org.apache.felix
maven捆绑插件
真的
org.gxkl.server,
...
...
错误消息意味着bundle
启动器导入包org.gxkl.server
,但框架中没有导出包的bundle
顺便说一下,您可以从POM中删除
部分。不需要它们。很抱歉这么晚才回复您。正如您在service
的pom文件中所看到的,我导出了org.gxkl.server
。但是为什么它在这个模块中不起作用呢?我不知道。POM是一个构建时构造,因此在构建和部署期间可能发生任何事情。我真的需要查看实际包的MANIFEST.MF。好吧,你说这是因为框架中没有导出包的包。因此,我重新检查了设置,发现我在felix的设置中犯了一个错误,因此felix在运行时找不到服务
包。现在,我的项目很好,谢谢你。