This was originally written by duncanidaho, and then I started using it almost a year ago, and added various bugfixes and improvements along the way.
http://javagamesfactory.org/views/view-sourcesnippet?id=1
This is an “Automatic class locater and loader”:
[] Supply a regexp filter defining a classname (e.g. "com.sun.") and ask it to find all classes anywhere on your classpath and in ANY jars that match that search
[] Provide a list of regexps that you want it to completely ignore (for increased performance, for instance), e.g. "org.apache." if you’re using some apache packages, and only want to find things in your packages
[] Find all classes that implement a given interface (Yes! Really!)
[] …or do it using a regexp to filter out unwanted subclass names / improve search performance
[] Produces a list of classes that were REQUIRED by some of the classes it found; tells you which classes required them (so you can decide if you care or not)
[] Extensive error handling so that it recovers from practially every possible failure (um; only by trial-and-error - I may have missed some - let me know if you hit any new ones, or spot something that should be handled and currently isn’t)
[*] …probably does some other stuff too that I’ve forgotten about
FYI it’s been running on every restart on the JGF server (auto-locates classes to be loaded to run parts of the system) for the last 6 months or so, and I’m pretty confident it’s robust now (although I found many fiddly little bugs and problems along the way).