I do not use JasperServer, instead I created a webapp using JasperReport 4.0.2 directly.
Templates are not in the default classloader, there are added, using a ContextClassLoader before calling JasperReport.
In recent version of Jasper Report font management changed as indicated in this document. Therefore I need to provide the Font JARs, which works when I put them in the WEB-INF/lib directory directly.
However, for modularity reasons I would like to add them to the classpath using the same ContextClassloader as done with the templates, but in that case, texts are not rendered with the correct font.
I do think this has something to do with the way JasperReport loads the Font.
Using a debugger I could track it back to the net.sf.jasperreports.engine.util.getFontInfo(...) method that does not return the same result.
This is due to the fact that ExtensionsEnvironment.getExtensionsRegistry().getExtensions(FontFamily.class) does not returns the same family list in both cases. Extensions are only loaded when JARs are place in WEB-INF/lib.
Does someone knows how the net.sf.jasperreports.extensions.getExtensionsRegistry() could be adapted to retrieve threadRegistry instance instead? (must be initialized somehow I guess).
This issue seems to be a duplicate of http://jasperforge.org/plugins/espforum/view.php?group_id=102&forumid=103&topicid=76180
When JasperReport load the extension (lazily, on first use) the font extension is uses JasperReport Classloader, not the context class loader.
JRLoader.collectResourcesthen get a list of all classloader by iterating on.getParent().Using
Thread.currentThread().getContextClassLoader()instead an handling errors should provide the extended classloader (which need to haveJRLoader.class.getClassLoader()set as parent).Changing the classloader used in JasperReport code fixes the issue but could however have side effects on other use cases.