I've been asked to periodically list - preferably in spreadsheet form - the public interface of our app's back end, its business tier. Specifically, what's wanted is a list of all the EJB methods that our app exposes publically.
Starting from a list of classes, this is pretty easy - the Reflection API provides all I need.
But getting that initial list of EJB classes in not so simple. There is apparently no method in the Java core classes to list a class's subsclasses, or all the classes in a package (either of which would suit).
I've googled this until the cows came home, and all I found were some kludges that go looking in the filesystem. Is there no better way to get a list of all the subclasses of a class, or all the classes in a package?
Have you considered Javadoc? It comes with your Java compiler, generates all the API information for you, for all your classes and all their methods (you can specify what visibility you want reported), provides grouping by packages, and lists found subclasses etc.
In case you have never seen the output of Javadoc before, here is the Javadoc from the J2SE source code, jumping directly to IOException. You can see packages in the top left hand corner, all classes in the bottom right hand corner, and the information for the class itself in the right hand side. You can see what the IOException extends, what interfaces it implements, and a whole list of classes that extend it.
Using the file i/o for this isn't a good option. Remember theoretically classes can be loaded from anywhere and its the classloader which is responsible for that.
Specifically, what's wanted is a list of all the EJB methods that our app exposes publically.
If you look at this more closely, it's exactly what each application server has to do too. It has to find out the business interfaces exposed by the EJBs and the business methods. As Jeanne said, this can be done if you either have access to the ejb-jar.xml files or for EJB3.x, if you know the bean implementation class (although it's not straightforward for EJB3.x which allows the annotations to be specified not just on the impl class but even the interfaces). Overall, it's just a matter of finding out the business interface of a bean (can be done easily by parsing ejb-jar.xml) and then listing the methods on that interface.