我正在 RCP 应用程序(2023-09,Java17)中集成 BIRT 报告引擎 (4.13)。
我希望捆绑包 (B) 能够向包含报告引擎的捆绑包 (R) 提交
rptdesign
。捆绑包 B 中的一份报告包含一个使用该捆绑包中的 Java 对象的脚本。包含该类的包由包 B 导出。
在报告包中,我确定报告的来源并相应地设置类加载器。
Bundle B 通过扩展调用 Bundle R,并且没有定义直接依赖关系。
Bundle bundle = org.eclipse.core.runtime.Platform.getBundle(getBundleIdFromUrl(reportDesign));
BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, bundleWiring.getClassLoader());
config.getAppContext().put(EngineConstants.APPCONTEXT_DATASET_CACHE_OPTION, Boolean.FALSE.toString());
config.getAppContext().put(EngineConstants.REFRESH_DATA, Boolean.TRUE.toString());
IReportEngineFactory factory = (IReportEngineFactory) Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
engine = factory.createReportEngine(config);
但是,当脚本执行时找不到类:
A BIRT exception occurred. See next exception for more information.
TypeError: [JavaPackage myapp.mech.model.Dao] is not a function, it is object. (/report/data-sets/script-data-set[@id="411"]/method[@name="open"]#1)
org.eclipse.birt.data.engine.core.DataException: Fail to execute script in function __bm_OPEN(). Source:
------
" + model = new Packages.myapp.mech.model.Dao();
(捆绑包 R 中的报告已正确处理)
我可以影响类加载还是这种方法基本上是不正确的?
我在这里找到了答案https://www.vogella.com/tutorials/EclipseBIRT/article.html#deploying-in-eclipse-rcp-application。
count = 0;
/*
* load and init data reader
* import Platform from org.eclipse.core.runtime
*/
importPackage(Packages.org.eclipse.core.runtime);
/* load bundle with POJOs and data loading class */
myBundle = Platform.getBundle("de.vogella.birt.stocks");
/* load data reader class */
readerClass = myBundle.loadClass("de.vogella.birt.stocks.daomock.StockDaoMock");
/* create new instance of DataReader */
readerInstance = readerClass.newInstance();
/* read data */
stock = readerInstance.getStockValues("Java");