Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Classpath issue when calling Java from script with BIRT runtime engine
hgu1
I have BIRT runtime integrated with our application to generate CSV reports with scheduled jobs (not via web viewer). In a report design, I need to call a remote API (proprietary) to get some data dynamically. I'm trying to use javascript in the report design to call a Java class to do it. I've packaged Java class into a jar and added the jar into the resource folder and then added the jar as a resource to the report design through the "Resources" tab. If the Java class does not reference any other jar files and simply return a string for example, everything works fine. But when it calls classes from other dependent jars, ClassNotFound exception is thrown. I've tried to add the dependent jars to ReportEngine\lib, or add the dependent jars using "Resources" tab, neither resolved the ClassNotFound issue. Any pointers?
Find more posts tagged with
Comments
JasonW
If you are using the RE API, make sure you set the parent classloader like:
//config is EngineConfig
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, yourreapiclass.class.getClassLoader());
You can add to the engine's classpath using:
EngineConstants.config.getAppContext().put(EngineConstants.WEBAPP_CLASSPATH_KEY, classpathstring);
Jason
hgu1
Hi Jason,
Since I'm not viewing the report using the web, setting EngineConstants.WEBAPP_CLASSPATH_KEY will not help. Could you explain what your first line of code does and what "yourreapiclass" would be in my case? If it's the class I'm using, I'm actually using multiple classes. Should I make the call for all classes one by one? Another issue is, the Java code that calls the Report Engine is generic. It would be nice to keep the code static without having to modify it each time when a new class is added.
Thanks,
Harry
JasonW
This constant EngineConstants.WEBAPP_CLASSPATH_KEY is not just for a web app, it is just used by the default example viewer to add to the classpath. You can also use EngineConstants.PROJECT_CLASSPATH_KEY. It is a classpath string. The other setting should just be done once by the class that creates the report engine. If the cp changes for that class it will be automatically picked up by the engine.
Jason
hgu1
Thanks a lot for the info. The first call has resolved my issue:
config.getAppContext().put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, yourreapiclass.class.getClassLoader());
"yourreapiclass" is the class that instantiates the report engine, as you've mentioned in your latest post. The call tells the engine to use the calling app's class loader to load the classes first.
Harry