In my project class path poi 2.5 version is already there and on runtime i want to load poi 3.5 jar as for two java classes in my project require poi 3.5 version , so for that I have written class loader that will call the poi 3.5 jar on runtime please advise what is wrong now as it is not loading poi 3.5 version jar at runtime
below is my classloader
public class MyClassLoader {
private static final Class[] parameters = new Class[] {URL.class};
public static void addFile(String s) throws IOException
{
File f = new File(s);
addFile(f);
}
public static void addFile(File f) throws IOException
{
addURL(f.toURI().toURL());
}
public static void addURL(URL u) throws IOException
{
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class;
try {
Method method = sysclass.getDeclaredMethod("addURL", parameters);
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");
}
}
}
and here i am calling from inside main method one of the method of poi 3.5 class which is newly added in 3.5 but it is not loaded
MyClassLoader.addFile("C:\\Release14branchupdated\\lib\\thirdparty\\POI-3.5\\poi-3.10-FINAL.jar");
Constructor<?> cs = ClassLoader.getSystemClassLoader().loadClass("org.apache.poi.ss.formula.FormulaCellCacheEntrySet").getConstructor(String.class);
System.out.println("$$$$$$$$$$"+cs.getName());
org.apache.poi.ss.formula.FormulaCellCacheEntrySet instance = (org.apache.poi.ss.formula.FormulaCellCacheEntrySet)cs.newInstance();
instance.iterator();
now upon execution the error that i am getting is not ble to find class FormulaCellCacheEntrySet