自动生成manifest.mf时如何管理导入和导出包

时间:2017-02-10 00:38:26

标签: maven osgi-bundle

我正在开发一个自动生成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)

围绕此类问题的所有解决方案都表示在导入和导出包中进行更改,但在项目中,清单会自动生成。

如何解决此问题的任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:2)

如果您使用maven-bundle-plugin,则可以使用

控制导出包
<Export-Package> and `<Import-Package>`

答案 1 :(得分:2)

对于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>