Post a Job  |   Ask a Question?   |   Already registered? login or register
Ranjit Kumar
25/11/2016 12:35 PM

CustomClassloader, can anyone help me and check my code..

Spam    15 Comments

25/11/2016 13:04:10
may this work... return super.findSystemClass(name);

25/11/2016 13:26:16
yup Vivek ,and one more is ,at the point of replace method u wrote '//' but it takes '/' only .try this and it works fine.

25/11/2016 14:13:51
String classFileName=name.replace(".","/")+".class;

25/11/2016 15:39:07
Thanx to All

26/11/2016 00:26:48
Ranjith can you tell me what you did am also getting CNF exception??? .......................................................................................................... Exception in thread "main" java.lang.NoClassDefFoundError: com/cc/beans/Toy at Caused by: java.lang.ClassNotFoundException: at$ at$ at Method) at at java.lang.ClassLoader.loadClass( at sun.misc.Launcher$AppClassLoader.loadClass( at java.lang.ClassLoader.loadClass( ... 1 more

26/11/2016 00:38:07
instead of String classFileName=name.replace(".", "//")+".class"; use String classFileName=name.replace(".", "/")+".class";

26/11/2016 00:56:05
//Logic for Custom Class Loader String baseDir ="G:\\classes\\"; String classFileName=name.replace(".", "//")+".class"; can you tell me plz why we r set that path and where i will be set that path ,i'm confused where i set that path....

26/11/2016 01:13:56
you don't need to set the path rather in case of IDE just remove the Toy.class from bin directory and then place it inside g:\classes\com\cc\beans\Toy.class folder with fully qualified our own custom class loader can be able to read the class byte code from that specific path and jvm will execute it.

26/11/2016 01:48:58
E:\Spring\CustomClassLoader\bin\com\ccl\beans/test/loader it's my work location,can u tell me plz where i will remove .class file and where i will be place....

26/11/2016 10:05:35
listen i have my work directory like d:\spring |-CustomClassLoader |-bin |-com |-ccl |-beans(Toy.class) |-test(Test.class) |-loader(MyClassLoader.class) u delete only that beans folder(Toy.class) and don't delete the whole package bcoz test and loader also refering to its package and place it in the specified directory with full package name like, g:\classes |-com |-ccl |-beans |-Toy.class try it.

26/11/2016 16:34:56
Class<?> clazz = super.defineClass(name,byteCode, 0, byteCode.length); here remove super keyword. then it should work. becoz, if u put super.defineClass(-,-,-,-); then it always look into class path. which is bin/src/com/cc/beans/Toy.class try it once. it should work.

26/11/2016 16:35:04
String baseDir ="G:\\classes\\"; String classFileName=name.replace(".", "//")+".class"; Instead use this String baseDir ="G:\\classes\\"; String classFileName=name.replace(".", "/")+".class"; and remove beans folder from E:\Spring\CustomClassLoader\bin/com/ccl/ and paste inside your location like G:\classes\com\ccl\beans\Toy.class It will work

27/11/2016 23:52:40
chandru,M don't worry your code is also correct, I think many of friends provide solution, there is not problem in code ,just you need to follow the rules it will work properly and remove super from super.defineClass(-,-,-,-);

27/11/2016 23:57:33
hell times i tried but not working , i cant getridoff this nullpointer exception. can any one upload your successed code in post......

29/11/2016 23:50:12

Languages :