Loading a class by absolute path

So I'm making a plug-in for eclipse with which I want to automatically generate test stubs for each of the public methods and constructors of a class. The way the plug-in works, you right click on the file in the navigation pane. At this point, java has created an IResource object to store the file data, and that's about it--so all I really know is the path and file name.

It's not really possible to modify the build path to incorporate all the classes, since the classes in a workspace are changing all the time and could be different for any user. Thus, I can't use Class.forName(String) to get it.

Is there a way of doing this knowing just the location of the class file in the file system? Otherwise, I'll have to parse the file manually to find all the methods.

Thanks

[809 byte] By [ducotta] at [2007-11-27 6:53:18]
# 1

Not really. You have to know both the location of the class in the file system and the name of the package it's in. When you load the class you have to load it via its full name, including package. And the package name corresponds to the last part of the directory path where the class is located.

DrClapa at 2007-7-12 18:28:00 > top of Java-index,Core,Core APIs...
# 2
If I can find out the name and package at runtime, is it possible?
ducotta at 2007-7-12 18:28:00 > top of Java-index,Core,Core APIs...
# 3

Actually, my last comment is a little misleading. The name and package are easy to find, but the problem is I wouldn't be importing that package at compile time, so java can't find the class I'm referencing. I'm guessing it's not possible to communicate this information (via the full path of the file on my hard drive) at runtime, but if anyone has any ideas let me know.

ducotta at 2007-7-12 18:28:00 > top of Java-index,Core,Core APIs...
# 4

> If I can find out the name and package at runtime, is it possible?

Sure. If you know that the class is in /you/data/classes/banana/org/salad.class and you know that the package is banana.org, then you open a URLClassLoader containing /you/data/classes and load the banana.org.salad class.

DrClapa at 2007-7-12 18:28:00 > top of Java-index,Core,Core APIs...