How to include resource file into osgi bundle from jar dependency with bnd/maven-bundle-plugin?
You can use the maven-dependency-plugin
to un-compress your dependencies jar and then include the resource in your 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>
The Include-Resource
instructions is supposed to be pom relative, see Include-Resource, you can probably replace target
with ${project.build.directory}
.
If you have a file reference to the jar, you can do
-includeresource: @path/to/file.jar!/some.xml
You use the @
prefix to say the resource is in the jar and the !/
syntax from jar urls.
The tricky part will be getting a path to the jar from the project dependencies I suspect.