We have a WebService that receives a name of a report and its parameters, and calls a JRPdfExporter.
Since the reports can be added at runtime by the users, we need a way to dynamically add the Jasper jar font file into the classpath, so that any new fonts added by the users can be added to Jasper classpath.
We are using this code to try and inject the new jar into the classpath but with no success
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;
try {
Method method = sysclass.getDeclaredMethod("addURL", new Class[]{URL.class});
method.setAccessible(true);
method.invoke(sysloader, new Object[] {u});
} catch (Throwable t) {
t.printStackTrace();
throw new IOException("Error, could not add URL to system classloader");
}
The error I'm getting is
net.sf.jasperreports.engine.JRRuntimeException: net.sf.jasperreports.engine.JRException: Input stream not found at : fonts/fontsfamily1415192514231.xml
Any ideas on how I can do this?
Or is there a better alternative?
I solved this problem by "simpling" searching a specific folder for JAR font files, opening them and uncompressing all the necessary files/folders.