Jump to content
Changes to the Jaspersoft community edition download ×

ClassLoader & ResourceBundle


Alesque

Recommended Posts

Hi,

 

I'm trying to fill a report enclosing images and a resource bundle.

 

Files of those resources are located into a specific folder outside the classpath, so I created a URLClassLoader which is sent via the parameter REPORT_CLASS_LOADER enabling the FillManager to load those files.

 

If I fill a report which only encloses images that works like a charm. But if the report references a resource bundle (i18n purpose), I get an exception telling that the bundle name is not found.

 

It seems that the FillManager doesn't use the classloader given in parameter to load the bundle referenced in the JRXML file.

 

Code:

// ClassLoader
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URLClassLoader loader = new URLClassLoader(new URL[] { templatePath.toURL() }, cl);

// Parameters
Map jasperParameters = new HashMap();
jasperParameters.put(JRParameter.REPORT_CLASS_LOADER, loader);
jasperParameters.put(JRParameter.REPORT_LOCALE, locale);

 

A simple workaround is to set the parameter JRParameter.REPORT_RESOURCE_BUNDLE

like this:

 

Code:
[code]
[...]
if (jasperReport.getResourceBundle() != null)
{
jasperParameters.put(JRParameter.REPORT_RESOURCE_BUNDLE,
ResourceBundle.getBundle(jasperReport.getResourceBundle(), locale, loader));
}

 

In the case a report references subreport, and the subreport references resource bundle, this workaround won't work.

 

Is this a bug of jasper report?

 

Any help would be appreciated.

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

  • 4 weeks later...
  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...