简体   繁体   English

如何使Barcode4J FOP Extension在OSGi中工作(用于使用条形码生成PDF)

[英]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. 使用JBoss Fuse,我有一个Camel-FOP端点组件,该组件可以成功生成PDF作为路由的一部分。 A new requirement is to include dynamic barcode generation in the PDF output. 一项新要求是在PDF输出中包括动态条形码生成。 This must run in the OSGi container. 它必须在OSGi容器中运行。 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. 尽管FOP和Barcode4J都是捆绑包,但FOP扩展(barcode4j-fop-ext:21)只是一个普通的jar,似乎没有可用的捆绑包版本。

I first tried to wrap the FOP extension via bnd and deployed it, however FOP does not find/see the extension. 我首先尝试通过bnd包装FOP扩展并将其部署,但是FOP找不到/看到该扩展。 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查找由类路径中的可选扩展提供的名为org.apache.fop.fo.ElementMapping的任何文本文件。 FOP then dynamically instantiates a class in the extension Jar using the class name provided within that text file - class.forName(...). 然后,FOP使用该文本文件中提供的类名称-class.forName(...)动态实例化扩展Jar中的类。

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. FOP Extension Jar将纯文本文件保存在META_INF / services下,并且必须对FOP包可见,以及Extension Jar中的几个Java包。 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. 此文本文件包含字符串“ org.krysalis.barcode4j.fop.BarcodeElementMapping”,它对应于FOP捆绑包必须实例化的FOP扩展内的类。

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. 编辑:我还应该补充一点,我已经查看了FOP软件包清单,并且没有可选的导入或对我正在使用的FOP Extension Jar的其他引用。 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? 有什么方法可以使它在OSGi中工作,还是我应该在寻找其他解决方案?

Sounds like your FOP is looking for service extensions. 听起来您的FOP正在寻找服务扩展。 Make sure you also have the Aries SPI-Fly feature installed. 确保您还安装了Aries SPI-Fly功能。 This feature looks for those service extensions META-INF/services and makes those available to other bundles requiring those extensions. 此功能将查找那些服务扩展META-INF / services,并使那些扩展可用于需要这些扩展的其他捆绑软件。 That should already do most of the work for you. 那应该已经为您完成了大部分工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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