简体   繁体   中英

How to get the Barcode4J FOP Extension to work in OSGi (for PDF generation with barcodes)

Working with JBoss Fuse, I have a Camel-FOP endpoint component that successfully generates PDFs as part of a route. A new requirement is to include dynamic barcode generation in the PDF output. This must run in the OSGi container. While both FOP and Barcode4J are bundles, the FOP Extension (barcode4j-fop-ext:21) is just a plain jar and no bundle version seems to be available.

I first tried to wrap the FOP extension via bnd and deployed it, however FOP does not find/see the extension. The way this works is that at runtime FOP looks for any text files named org.apache.fop.fo.ElementMapping supplied by optional extensions in the classpath. FOP then dynamically instantiates a class in the extension Jar using the class name provided within that text file - class.forName(...).

The FOP Extension Jar keeps the plain text files under META_INF/services which must be visible to the FOP bundle, as well as several Java packages in the Extension Jar. This text file contains the string "org.krysalis.barcode4j.fop.BarcodeElementMapping" that corresponds to the class within the FOP Extension that the FOP bundle must instantiate.

EDIT: I should add also that I've looked at the FOP bundle manifest, and there is no optional import or other reference to the FOP Extension Jar I'm using. The idea with the extensions I think is that they are runtime discoverable, and thus not implicitly referred to.

Is there any way to get this to work in OSGi, or should I be looking at other solutions?

Sounds like your FOP is looking for service extensions. Make sure you also have the Aries SPI-Fly feature installed. This feature looks for those service extensions META-INF/services and makes those available to other bundles requiring those extensions. That should already do most of the work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM