使用Maven-bundle-plugin的所有资源的<Export-Package>

Hil*_*kus 4 osgi maven maven-bundle-plugin

作为能够快速过渡到OSGi的临时措施,我需要创建一个包含所有库的单个jar。我所做的就是将所有jar库都放在src / main / resources中,以便它们最终位于创建的jar的根目录中。我遇到的问题是告诉Maven-bundle-plugin导出jar中的所有软件包。所以基本上,我想将所有库公开给其他OSGi捆绑软件

这是我在POM中尝试的第一件事

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Export-Package>*</Export-Package>
                    <Bundle-Name>${project.artifactId}</Bundle-Name>
                    <Bundle-Version>${project.version}</Bundle-Version>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>`
Run Code Online (Sandbox Code Playgroud)

我试图导出那里的所有东西。但是似乎唯一这样导出的是两个osgi依赖关系,而不是资源中的jars

我有一百多个库,因此我试图找到一种自动填充<Export-Package>指令的方法,而不是手动添加每个librarie的软件包。eclipse在插件开发环境中以某种方式做到了这一点,但是我需要使用maven做到这一点。捆绑插件完全有可能吗?如果将罐子添加到罐子中,则需要加分<Bundle-ClassPath>

cst*_*roe 5

您必须将jar作为依赖项添加到pom.xml中,然后在<build>标记中对maven-bundle-plugin使用以下公式:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <manifestLocation>META-INF</manifestLocation>
        <instructions>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Bundle-Version>${project.version}</Bundle-Version>
            <Export-Package>*</Export-Package>
            <Bundle-Activator>your.activator.package.Activator</Bundle-Activator>
            <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
            <Embed-Directory>target/dependency</Embed-Directory>
            <Embed-StripGroup>true</Embed-StripGroup>
            <Embed-Transitive>true</Embed-Transitive>
        </instructions>
    </configuration>
</plugin>

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

还要添加以下内容,以使所有内容都适用于m2e:

请参阅:m2e不支持maven-dependency-plugin(目标为“ copy-dependencies”,“ unpack”)

<pluginManagement>
    <plugins>
        <!-- Ignore/Execute plugin execution -->
    <plugin>
            <groupId>org.eclipse.m2e</groupId>
            <artifactId>lifecycle-mapping</artifactId>
            <version>1.0.0</version>
            <configuration>
                <lifecycleMappingMetadata>
                    <pluginExecutions>
                        <!-- copy-dependency plugin -->
                        <pluginExecution>
                <pluginExecutionFilter>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-dependency-plugin</artifactId>
                                <versionRange>[1.0.0,)</versionRange>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                            </pluginExecutionFilter>
                            <action>
                                <ignore />
                            </action>
                        </pluginExecution>
                    </pluginExecutions>
                </lifecycleMappingMetadata>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>
Run Code Online (Sandbox Code Playgroud)

还添加以下内容以使其与Eclipse PDE一起使用(取自Apache Felix网站):

<profiles>
    <profile>
        <activation>
            <property>
                <name>m2e.version</name>
            </property>
        </activation>
        <properties>
            <osgi-version-qualifier>qualifier</osgi-version-qualifier>
        </properties>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.felix</groupId>
                        <artifactId>maven-bundle-plugin</artifactId>
                        <configuration>
                            <!-- PDE does not honour custom manifest location -->
                            <manifestLocation>META-INF</manifestLocation>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)