OSGi:缺少要求 osgi.wiring.package
OSGi: Missing requirement osgi.wiring.package
我写了一个包含 5 个模块的项目。我使用 maven 在 intellij IDEA 中创建它们,然后向所有模块添加 "OSGi" 框架支持。我使用 maven-bundle-plugin 来配置导出包和导入包。但是当我运行的时候,总是报错:
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).
launcher模块包含Bundle-Activator,org.gxkl.server包在service模块中。我使用类似的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>
服务中的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>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>
错误信息的意思是bundle launcher
imports package org.gxkl.server
但是framework中没有bundle导出包。
顺便说一下,您可以从 POM 中删除 <Import-Package>
部分。不需要它们。
我写了一个包含 5 个模块的项目。我使用 maven 在 intellij IDEA 中创建它们,然后向所有模块添加 "OSGi" 框架支持。我使用 maven-bundle-plugin 来配置导出包和导入包。但是当我运行的时候,总是报错:
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).
launcher模块包含Bundle-Activator,org.gxkl.server包在service模块中。我使用类似的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>
服务中的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>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>
错误信息的意思是bundle launcher
imports package org.gxkl.server
但是framework中没有bundle导出包。
顺便说一下,您可以从 POM 中删除 <Import-Package>
部分。不需要它们。