Finding source files programatically
Suppose I have a class com.foo.Test. In that class, I want to add a method, File[] getSourceFiles() which will find the directory in which Test.class resides and return the names of all the other class files in that directory.
The problem I'm having, is that I can't get a reference to the directory containing Test.class. I can get the path information "com/foo", but I can't get the location of the "com" directory.
Is there a way to do this?
Thanks.
You can find the classpath and the location of the extensions directory from certain system properties (not sure which ones, just dump them all and you'll recognize them). Given them, you have a list of directories and jar files which you can then examine sequentially. Don't forget that your class could be in a jar file, it doesn't have to be in a directory.
Thanks!That's exactly what I was looking for. I knew this information had to be somewhere in the ClassLoader instance, but I couldn't find where. Now I know to get it through the getResource() method.Thanks, again.Scott