Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Generating a report within an EJB.
llazzeri
<p>I have an EJB module which generates Birt Reports. The module contains the code to invoke the Report Engine and a couple of folders for the .rptdesign end resource files.</p>
<p> </p>
<p>Everything works fine when the module is deployed exploded, but when it is deployed as a jar (which is the most common case) I have a problem in providing the resource path to the engine.</p>
<p>I use the following code:</p>
<p><span style="font-family:'courier new', courier, monospace;">URL url = this.getClass.getResource("/" + BIRT_LIBRARIES);</span></p>
<div><span style="font-family:'courier new', courier, monospace;">config.setResourcePath(url.getPath());</span></div>
<div>The path that I get (something like C:/Oracle/Middleware/user_projects/.../.../.../.../BirtEJB.jar!/reports/libraries) doesn't make any sense to the engine, and I get the error "Resource not accessible" (of course).</div>
<div> </div>
<div>Is there any way to access a resource folder when this is embedded in a jar?</div>
<div> </div>
<div> </div>
<div>Any help is appreciated.</div>
<div>Regards,</div>
<div>Livio</div>
Find more posts tagged with
Comments
llazzeri
<p>I solved the problem myself.</p>
<p>To the EngineConfig, instead of providing the resource path, I provide a custom ResourceLocator:</p>
<p><span style="font-family:'courier new', courier, monospace;">config.setResourceLocator(new MyResourceLocator());</span></p>
<p> </p>
<p>A ResourceLocator, when it is invoked, must return the URL of the searched resource. The URL of a resource embedded in a jar which is in the classpath, can be easily found via the class loader:</p>
<p><span style="font-family:'courier new', courier, monospace;">classLoader.getResource(<em>BIRT_LIBRARIES</em> + fileName);</span></p>
<p>where BIRT_LIBRARIES is the resource folder to search. It must start and end with "/" (for example: "/reports/libraries/").</p>
<p>This URL is quite strange, at least for me. Its protocol is zip:.</p>
<p> </p>
<p>As an example of ResourceLocator I took the class <span style="font-family:'courier new', courier, monospace;">org.eclipse.birt.report.model.util.ResourceLocatorImplBase</span>, which I found in the Birt sources. In that class I simply changed the last instruction of the method <span style="font-family:'courier new', courier, monospace;">tryFragmentSearch()</span>, in order to get the URL as explained above.</p>
<p> </p>
<p>Regards,</p>
<p>Livio</p>