i am developing a plug in which deals with hibernate project.I get some classes 开发者_运维问答which contain Session and Session factory .Then i want to instantiate an object of these classes using reflections which i am not able to do it even after including the hibernate jars in the classpath of my plug in.What is the problem?Help
Here is the code
String hibernate_jars = "C:\\Documents and Settings\\Administrator\\My Documents\\hibernate_jars\\lib.folder\\lib";
URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
Class sysclass = URLClassLoader.class ;
Method method = sysclass.getDeclaredMethod("addURL",URL.class);
method.invoke(sysloader, new Object[] { new File(hibernate_jars).toURI().toURL() });
clss = Class.forName("test.Example", false, ClassLoader);
Object myobj = clss.newInstance();
unable to create the instance and its not giving any exceptions either.
You may need to call method.setAccessible(true); before you invoke it
精彩评论