[Logo]
Forums Register Login
java class loader basic question..
Hi there, i have a basic java class loader question here,

with com.mycompany.app.class1, is the path of a class which i intend to load and its inside the same package as my current class.
But the class 'c' loaded is always null, perhaps this is not the correct way? The following is the content customclassloader.java which i get from some resources on the internet.



Please guide or help or comment, thanks in advance.
 


}catch(Exception e){
return null;
}


You need to put in some proper error handling, like at least notifying you if there is a problem.

I'm also not quite sure what the point of this ClassLoader is - after a cursory inspection it seems to look at the classpath, so any classes would be loaded by the standard classloaders, and never by the loadClassData method.

String classPath = ((String)ClassLoader.getSystemResource(className.replace('.',File.separatorChar)+".class").getFile()).substring(1);


This line looks rather strange to me; what's it supposed to do?

I'll move this to the Intermediate forum - loading classes is not beginner stuff.
pie. tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA


This thread has been viewed 778 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 17, 2018 05:45:56.