如何使用 bnd/maven-bundle-plugin 从 jar 依赖项将资源文件包含到 osgi 包中?

uvs*_*tid 8 osgi bnd maven-bundle-plugin osgi-bundle

我正在使用maven-bundle-pluginbnd有效)。

从源中包含资源文件很简单。

例如,在构建期间将资源文件 ( src/main/resources/some.xml) 移动到target目录 ( target/classes/some.xml)下,可以使用以下<Include-Resource>指令将其包含到包中:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>3.0.1</version>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Include-Resource>
                some.xml=target/classes/some.xml,
            </Include-Resource>
        </instructions>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

让我们有一个依赖:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>library</artifactId>
    <version>1.0.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

如何在依赖中引用资源文件jar

换句话说,如何

所以来自依赖项之一的资源出现在输出包中jar

Ale*_*nis 7

您可以使用 解maven-dependency-plugin压缩您的依赖项 jar,然后将资源包含在您的 jar 中。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack-dependencies</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <markersDirectory>${project.build.directory}/dependencies/dependency-maven-plugin-markers</markersDirectory>
                <artifactItems>
                    <artifactItem>
                        <groupId>DEPENDENCY_GROUPID</groupId>
                        <artifactId>DEPENDENCY_ARTIFACTID</artifactId>
                        <type>OPTIONAL_DEPENCENCY_TYPE</type>
                        <outputDirectory>${project.build.directory}/dependencies/DEPENDENCY_ARTIFACTID</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>
...
<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <configuration>
        ...
        <instructions>
            ...
            <Include-Resource>target/dependencies/DEPENDENCY_ARTIFACTID/some.xml</Bundle-Activator>
        </instructions>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

Include-Resource指令被认为相对POM是,看到包括-资源,你也许可以代替target${project.build.directory}