开发者

Unable to instantiate class containing Hibernate code

开发者 https://www.devze.com 2022-12-24 23:23 出处:网络
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 re

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

0

精彩评论

暂无评论...
验证码 换一张
取 消