how to get Classes from package ?
I think I'm a dumpass, cause I cannot figure it out...
If I have a package, now how can I get all the classes in this package ? It is for a special documentation of two packages (and no, javadoc won't do the job) and I would be very thankful if someone could help me.
I just want to give the Package-Name and the method should return me all classes of this package...
[403 byte] By [
Xanatos] at [2007-9-26 2:21:27]

You can't do this. Java is a dynamically linked language, and you can in fact create new classes at runtime. Therefore, you cannot know all the classes that could be inside a package.
What you can do is go through all the classes within a directory or a JAR file, and see if they are part of the package you are interested in.
Hi! Here's a quick outline.
Browse the JAR file (or directory). Look at the java.util.jar and the java.util.zip packages for the required classes and docs.
Load every class you find. Use the loadClass() method in the java.lang.ClassLoader class. Record the name of every class in a data structure, eg. a hashtable, vector, etc.
Then, enumerate through the above data structure you used. For every entry in it, call the static forName() method in java.lang.Class class. This will return a matching Class object. Call getPackage() on this class object to get a Package object. Call getName() on this Package object and compare it with the reference package name you have. If there's a match, store the class name in another vector. The latter contains the "matching" class names.
At the end of the above process, you'll have a list of class names that are contained in the package of interest. Caveat : this will work with classes that are loaded, i.e. if you want to include dynamically created classes, then you'll have to make some modifications.
I have not tested this out since time is rather limited. However, should you have questions, feel free to ask.
Hope this helps!
Cheers!
amolk at 2007-6-29 9:26:42 >
