如何配置 maven-bundle-plugin

How to configure maven-bundle-plugin

我正在尝试转换 Eclipse 插件项目以使用 Maven。我现有的项目有以下 MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Message Level Security Plugin
Bundle-SymbolicName: com.mls;singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: MLS
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: com.ghc.ghTester.expressions
Bundle-ClassPath: lib/commons-logging-1.1.1.jar,
 lib/log4j-1.2.15.jar,
 .
Require-Bundle: org.bouncycastle.crypto;bundle-version="1.46.0",
 javax.xml;bundle-version="1.3.4",
 org.apache.wss4j;bundle-version="1.5.11",
 org.apache.xml.security;bundle-version="1.4.3002",
 org.apache.commons.lang;bundle-version="2.6.0"

但我在弄清楚如何配置 maven-bundle-plugin 以正确生成我的 OSGI 包时遇到了很多困难:

我试过:

    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>3.0.0</version>
        <extensions>true</extensions>
        <configuration>
            <instructions>
                <Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
                <Bundle-Name>${pom.name}</Bundle-Name>
                <Bundle-Version>${pom.version}</Bundle-Version>
                <Bundle-ClassPath>{maven-dependencies},.</Bundle-ClassPath>
                <Embed-Dependency>*;scope=compile|provided</Embed-Dependency>
                <Import-Package>com.ghc.ghTester.expressions</Import-Package>
            </instructions>
        </configuration>
    </plugin>

但是如何生成 "Require-Bundle" 条目以使用我列为 "provided" 的 Maven 依赖项?

例如:

<dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.6</version>
    <scope>provided</scope>
</dependency>

我是否必须以不同方式声明我的依赖关系?

您可以在 pom 中明确添加您的 Require-Bundle :

<Require-Bundle>org.bouncycastle.crypto;bundle-version="1.46.0", ...</Require-Bundle>

但是,Require-Bundle 是一种不好的(旧的?)做法。 bndtools,后面的maven-bundle-plugin可以为你生成合适的Import-Package。你不应该再使用 Require-Bundle header。

此外:

  1. 1.4.0 是一个非常旧的版本 (2008)。尝试使用最新版本,3.0.1
  2. 添加一个空的 <Export-Package/> 标签:默认情况下,此插件会导出除 *.internal.* *.impl.* 之外的所有包。如果您的包不使用此约定,则可能会导出包的内部 类。