Unload fonts and scriptlets from classpath

I am using jasperreports library to generate reports. I am trying to change classpath at runtime to be able to update fonts and scriptlets files. 
When I need to add new files to classpath I create new ClassLoader and pass new files as URL[] to it's contructor. After that I set the classloader to current thread. The library generates documents properly with new fonts and scriptlets. But when I want to remove old version of the files (after generation is complete) I can't do it because of java.io.IOExceprtion: Cannot delete. Looks like the files are still used by some part of Jasperreports library. 
Here is the code which I use to create class loader with new files:
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();try {    contextClassLoader.close();} catch (Throwable throwable) {    throwable.printStackTrace();}ClassLoader classLoader = new URLClassLoader(filesForClasspath.toArray(new URL[filesForClasspath.size()]));Thread.currentThread().setContextClassLoader(classLoader);
What do I do wrong? How classpath update should be done properly to be able to remove files that I don't need anymore?
eugene s's picture
Joined: Feb 19 2016 - 8:36am
Last seen: 2 years 6 months ago

0 Answers:

No answers yet