Мне удалось добавить специфичные для OSGi метаданные в МАНИФЕСТ артефакта Maven с летающей тарелкой-pdf. Однако мне не удается внедрить зависимости и транзитивные зависимости этого артефакта в созданный файл JAR.
Я использовал оригинальные исходники из файла fly-saucer-pdf, взятые с GitHub [1], и добавил следующие утверждения в файл pom.xml:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<instructions>
<Embed-Dependency>itext</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
Артефакт имеет зависимость, объявленную для itext версии 2.1.7 в его исходном файле pom.xml, который я не трогал. Я также не стал возиться с оригинальным типом упаковки артефакта, который представляет собой банку.
К сожалению, это только часть работы. MANIFEST.MF кажется правильным и содержит ожидаемые теги OSGi:
Manifest-Version: 1.0
Bundle-Description: Flying Saucer is a CSS 2.1 renderer written in Jav
a. This artifact supports PDF output.
Bundle-License: http://www.gnu.org/licenses/lgpl.html
Bundle-SymbolicName: org.xhtmlrenderer.flying-saucer-pdf
Archiver-Version: Plexus Archiver
Built-By: u0400072
Bnd-LastModified: 1478168053263
Bundle-ManifestVersion: 2
Embed-Dependency: itext
Import-Package: com.apple.mrj,com.lowagie.toolbox,javax.crypto,javax.i
mageio,javax.imageio.metadata,javax.imageio.plugins.jpeg,javax.imagei
o.stream,javax.swing,javax.xml.parsers,javax.xml.transform,javax.xml.
transform.dom,javax.xml.transform.sax,javax.xml.transform.stream,org.
bouncycastle.asn1,org.bouncycastle.asn1.cmp,org.bouncycastle.asn1.cms
,org.bouncycastle.asn1.ocsp,org.bouncycastle.asn1.pkcs,org.bouncycast
le.asn1.tsp,org.bouncycastle.asn1.x509,org.bouncycastle.cms,org.bounc
ycastle.crypto,org.bouncycastle.crypto.engines,org.bouncycastle.crypt
o.modes,org.bouncycastle.crypto.paddings,org.bouncycastle.crypto.para
ms,org.bouncycastle.jce.provider,org.bouncycastle.ocsp,org.bouncycast
le.tsp,org.w3c.dom,org.xhtmlrenderer.context,org.xhtmlrenderer.css.co
nstants,org.xhtmlrenderer.css.extend,org.xhtmlrenderer.css.parser,org
.xhtmlrenderer.css.sheet,org.xhtmlrenderer.css.style,org.xhtmlrendere
r.css.style.derived,org.xhtmlrenderer.css.value,org.xhtmlrenderer.ext
end,org.xhtmlrenderer.layout,org.xhtmlrenderer.render,org.xhtmlrender
er.resource,org.xhtmlrenderer.simple.extend,org.xhtmlrenderer.swing,o
rg.xhtmlrenderer.util,org.xml.sax,org.xml.sax.helpers
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
Tool: Bnd-3.2.0.201605172007
Embedded-Artifacts: itext-2.1.7.jar;g="com.lowagie";a="itext";v="2.1.7
"
Export-Package: org.xhtmlrenderer.pdf;uses:="org.w3c.dom,org.xhtmlrend
erer.css.constants,org.xhtmlrenderer.css.parser,org.xhtmlrenderer.css
.style,org.xhtmlrenderer.css.value,org.xhtmlrenderer.extend,org.xhtml
renderer.layout,org.xhtmlrenderer.render,org.xhtmlrenderer.resource,o
rg.xhtmlrenderer.simple.extend,org.xhtmlrenderer.swing,org.xml.sax";v
ersion="9.0.10",org.xhtmlrenderer.pdf.util;uses:="org.w3c.dom,org.xht
mlrenderer.pdf";version="9.0.10",org.xhtmlrenderer.simple;uses:="java
x.swing,org.w3c.dom,org.xhtmlrenderer.css.extend,org.xhtmlrenderer.cs
s.sheet,org.xhtmlrenderer.extend,org.xhtmlrenderer.layout,org.xhtmlre
nderer.swing,org.xhtmlrenderer.util";version="9.0.10"
Bundle-Name: Flying Saucer PDF Rendering
Bundle-Version: 9.0.10.SNAPSHOT
Bundle-ClassPath: .,itext-2.1.7.jar
Embed-Transitive: true
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_102
Но библиотека itext не помещается в результирующий JAR, т. е. запись Bundle-ClassPath МАНИФЕСТА указывает на отсутствующее содержимое.
Кроме того, я попытался создать совершенно новый артефакт, который объявляет зависимость от исходного артефакта «летающая тарелка-pdf» и повторно объединяет его в виде пакета OSGi, содержащего этот ответ [2] здесь, на StackOverflow, и это сработало.
Единственная реальная разница, которую я вижу, это тип упаковки «комплект» и «банка». Но я не могу изменить этот тип упаковки в исходном артефакте «летающая тарелка-pdf», так как все должно оставаться как есть для не-OSGi-использований, чтобы это изменение было принято как push-запрос.
Ребята, вы знаете, может ли это встраивание зависимостей с плагином maven-bundle-plugin работать с типом упаковки «jar»? Или ему нужен тип упаковки «комплект»?
Я ценю любой ответ и намек на то, что я мог бы попытаться выполнить повторное объединение непосредственно в исходном артефакте.
Спасибо большое.
С уважением Тимо Рорберг