I would write an Annotation Processor which gathers the classes. It could even write a class out which builds an instance of each.
Yes, this. If it's your code don't do the class listing thing. It's horrible! I hadn't quite twigged that when I replied.
If you only have that few classes you could even manage a registry class manually, but the use of an annotation processor to do this is a good idea.
The other standard way you could do this is via ServiceLoader (assuming they all subclass or implement the same type). This is great for allowing such types to be plugged in from other JARs too. There are pre-existing annotation processing libraries that can build the META-INF list automatically.
I've been digging around your guys responses. Interesting stuff! Like you suggested, I don't think listing each class is the best way to go about this. It's quite slow, and requires a lot of error checking when using against a lot of libraries (LWJGL, JBullet, ect). It actually throws some odd errors that refuse to be caught by a generic try catch Exception. I had to manually write each exception type specifically. In the end it just led to a JVM crash from LWJGL somewhere. I'm not going to report it as a LWJGL bug, it's clearly not. This is just too messy!
All of those classes do extend a common super-type; an abstract class. I'll see if I can implement something with the ServiceLoader.
I've also seen this library:
https://github.com/ronmamo/reflectionsPerhaps it's also a viable solution. I'll check it out soon
