自动生成 manifest.mf 时如何管理导入和导出包
How to manage import and export packages when manifest.mf is autogenerated
我正在开发一个自动生成 MANIFEST.MF
的项目。
当我在 Felix 控制台中部署我的 OSGi 包时,我可以看到依赖性问题
> 09.02.2017 08:15:16.258 *ERROR* [FelixDispatchQueue] xxx.core FrameworkEvent ERROR (org.osgi.framework.BundleException: Unresolved
> constraint in bundle xxx.core [446]: Unable to resolve 446.1: missing
> requirement [446.1] osgi.wiring.package;
> (&(osgi.wiring.package=xxx.acs.commons.dispatcher)(version>=1.0.0)(!(version>=2.0.0))))
> org.osgi.framework.BundleException: Unresolved constraint in bundle
> xxx.core [446]: Unable to resolve 446.1: missing requirement [446.1]
> osgi.wiring.package;
> (&(osgi.wiring.package=xxx.acs.commons.dispatcher)(version>=1.0.0)(!(version>=2.0.0)))
> at
> org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4095)
> at org.apache.felix.framework.Felix.startBundle(Felix.java:2114) at
> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1368)
> at
> org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
> at java.lang.Thread.run(Thread.java:745)
围绕此类问题的所有解决方案都说在导入和导出包中进行更改,但在项目中,清单是自动生成的。
任何有关如何解决此问题的帮助将不胜感激。
如果您使用 maven-bundle-plugin,您可以使用
控制导出包
<Export-Package> and `<Import-Package>`
对于maven项目可以使用maven-bundle-plugin。
对于其他标准 java 库使用 BND Tools,maven-bundle 插件也将其用作 api。
重新打包 apache-poi 并添加所需清单条目的 pom.xml 示例:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>3.13.1</version>
<properties>
<poi.version>3.13</poi.version>
<poi.schema.version>1.1</poi.schema.version>
<poi.security.version>1.0</poi.security.version>
</properties>
<groupId>your.group.id</groupId>
<artifactId>external-apache-poi</artifactId>
<packaging>bundle</packaging>
<name>external-apache-poi</name>
<description>Apache poi framework</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
<_exportcontents>
org.apache.poi.*;version=${poi.version},
org.openxmlformats.schemas.*;version=${poi.schema.version},
schemasMicrosoftComOfficeExcel.*;version=${poi.schema.version},
schemasMicrosoftComOfficeOffice.*;version=${poi.schema.version},
schemasMicrosoftComOfficePowerpoint.*;version=${poi.schema.version},
schemasMicrosoftComVml.*;version=${poi.schema.version},
org.etsi.uri.*;version=${poi.security.version}
</_exportcontents>
<Import-Package>
com.sun.javadoc;resolution:=optional,
com.sun.tools.javadoc;resolution:=optional,
org.apache.crimson.jaxp;resolution:=optional,
org.apache.tools.ant;resolution:=optional,
org.apache.tools.ant.taskdefs;resolution:=optional,
org.apache.tools.ant.types;resolution:=optional,
junit.framework.*;resolution:=optional,
junit.textui.*;resolution:=optional,
org.junit.*;resolution:=optional,
org.apache.xml.security.*;resolution:=optional,
org.apache.jcp.xml.dsig.internal.dom.*;resolution:=optional,
*
</Import-Package>
<DynamicImport-Package>
org.apache.xmlbeans.*,
schemaorg_apache_xmlbeans.*
</DynamicImport-Package>
<!-- bundle supplied resource prefixes -->
<Include-Resource>{maven-resources}</Include-Resource>
<!-- Do not inline jars, include as jar files -->
<!-- There are config files with same name will be overwritten -->
<Embed-Dependency>*;scope=compile;inline=false</Embed-Dependency>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Embedded dependencies -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>${poi.schema.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-security</artifactId>
<version>${poi.security.version}</version>
</dependency>
</dependencies>
</project>
我正在开发一个自动生成 MANIFEST.MF
的项目。
当我在 Felix 控制台中部署我的 OSGi 包时,我可以看到依赖性问题
> 09.02.2017 08:15:16.258 *ERROR* [FelixDispatchQueue] xxx.core FrameworkEvent ERROR (org.osgi.framework.BundleException: Unresolved
> constraint in bundle xxx.core [446]: Unable to resolve 446.1: missing
> requirement [446.1] osgi.wiring.package;
> (&(osgi.wiring.package=xxx.acs.commons.dispatcher)(version>=1.0.0)(!(version>=2.0.0))))
> org.osgi.framework.BundleException: Unresolved constraint in bundle
> xxx.core [446]: Unable to resolve 446.1: missing requirement [446.1]
> osgi.wiring.package;
> (&(osgi.wiring.package=xxx.acs.commons.dispatcher)(version>=1.0.0)(!(version>=2.0.0)))
> at
> org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4095)
> at org.apache.felix.framework.Felix.startBundle(Felix.java:2114) at
> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1368)
> at
> org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
> at java.lang.Thread.run(Thread.java:745)
围绕此类问题的所有解决方案都说在导入和导出包中进行更改,但在项目中,清单是自动生成的。
任何有关如何解决此问题的帮助将不胜感激。
如果您使用 maven-bundle-plugin,您可以使用
控制导出包<Export-Package> and `<Import-Package>`
对于maven项目可以使用maven-bundle-plugin。
对于其他标准 java 库使用 BND Tools,maven-bundle 插件也将其用作 api。
重新打包 apache-poi 并添加所需清单条目的 pom.xml 示例:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>3.13.1</version>
<properties>
<poi.version>3.13</poi.version>
<poi.schema.version>1.1</poi.schema.version>
<poi.security.version>1.0</poi.security.version>
</properties>
<groupId>your.group.id</groupId>
<artifactId>external-apache-poi</artifactId>
<packaging>bundle</packaging>
<name>external-apache-poi</name>
<description>Apache poi framework</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.5.3</version>
<extensions>true</extensions>
<configuration>
<instructions>
<_exportcontents>
org.apache.poi.*;version=${poi.version},
org.openxmlformats.schemas.*;version=${poi.schema.version},
schemasMicrosoftComOfficeExcel.*;version=${poi.schema.version},
schemasMicrosoftComOfficeOffice.*;version=${poi.schema.version},
schemasMicrosoftComOfficePowerpoint.*;version=${poi.schema.version},
schemasMicrosoftComVml.*;version=${poi.schema.version},
org.etsi.uri.*;version=${poi.security.version}
</_exportcontents>
<Import-Package>
com.sun.javadoc;resolution:=optional,
com.sun.tools.javadoc;resolution:=optional,
org.apache.crimson.jaxp;resolution:=optional,
org.apache.tools.ant;resolution:=optional,
org.apache.tools.ant.taskdefs;resolution:=optional,
org.apache.tools.ant.types;resolution:=optional,
junit.framework.*;resolution:=optional,
junit.textui.*;resolution:=optional,
org.junit.*;resolution:=optional,
org.apache.xml.security.*;resolution:=optional,
org.apache.jcp.xml.dsig.internal.dom.*;resolution:=optional,
*
</Import-Package>
<DynamicImport-Package>
org.apache.xmlbeans.*,
schemaorg_apache_xmlbeans.*
</DynamicImport-Package>
<!-- bundle supplied resource prefixes -->
<Include-Resource>{maven-resources}</Include-Resource>
<!-- Do not inline jars, include as jar files -->
<!-- There are config files with same name will be overwritten -->
<Embed-Dependency>*;scope=compile;inline=false</Embed-Dependency>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- Embedded dependencies -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-schemas</artifactId>
<version>${poi.schema.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>ooxml-security</artifactId>
<version>${poi.security.version}</version>
</dependency>
</dependencies>
</project>