File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes java class loader basic question.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java class loader basic question.." Watch "java class loader basic question.." New topic
Author

java class loader basic question..

Cloey Tan
Ranch Hand

Joined: Feb 03, 2009
Posts: 60
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.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43

}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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java class loader basic question..
 
Similar Threads
I need help with custom ClassLoader's
Executing Singleton class with Custom Class Loaders
loadClass, defineClass (run-time loading)
New Java, old CORBA
my loader not working