Re: annotation metadata proposal
On 10/31/2014 12:06 AM, email@example.com wrote:
Suppose I wrote 2 classes summer.sports.Soccer and winter.sports.Hockey each in their own jar (soccer.jar and hockey.jar). Each class is annotation @Sport. Now at runtime, I want to find all classes annotated with @Sport.
Scanning all jars is kinda expensive.
The alternative is to have a properties file where you can list all such classes or better yet packages that contain those classes. Each jar file would have such a properties file.
But it is tedious to maintain such list.
Note I allow new sports jar added, I can not specify the packages using something like Spring framework's component:scan(packages) because I can not predict future.
I think tools can help.
a) add an file in jar: META-INF/annotated-classes
b) format: full.class.name:Ann1,Ann2, one class per line
c) mvn plugin to generate META-INF/annotated-classes and package it in jar/war
d) IDE: when building a project generate such entry and put in output folder (e.g. target/classes)
e) provide library to read all META-INF/annotated-classes
What do you think?
I think: "*Why* do you need to find all the @Sport-annotated classes
I can see why it's useful to find all something-or-other classes (or
packages, or other things) at runtime: That's how things like Swing
look-and-feel implementions get found, not to mention crypto plugins,
fonts, and a good deal of other stuff that lives "in the environment."
My question isn't why you want to find something, but why you want to
use annotations as the search keys (or filters). For one thing, it
seems rather limiting: You could only search for annotatable things,
so fonts and DLL's and other such artifacts would be forever invisible.
In a follow-up, you refer to "hundreds if not thousands of classes,"
which makes me wonder whether class-at-a-time annotation is a scalable
way to organize things. Isn't there a higher-level taxonomy of some
kind you could take advantage of? How many thousands of sports are
What is the problem you face? Can you describe it concretely
without breaching too many confidences?