I'm not sure how an annotation (or a config file, for that matter) can help with creating a plugin. It might help the class find an associated plugin, e.g. if the classname of the plugin was part of the annotation.
Personally I use an XML configuration file for plugin architecture because of the flexibility. Adding a new class that has different initialization requirements does not disturb any of the existing configurations. Its so easy to give every plugin class a method:
What do you think of Sun's Service Provider Interface (SPI) approach in combination with Annotations for creating plugins?
I don't know why Sun's SPI approach was never described in a blueprint document, at least AFAIK. Sun itself heavily use the SPI approach.
So why not use it similar in our own products or applications. One could write an Annotation Processor Factory and a special Annotation so that the configuration is stored during compile time into some META-INF/service configuration file? Each concrete class would then get such special annotation.
Wouldn't that be more convenient and less error prone than doing it manually?
Sun's service provider interface is a neat way to be able to plug in services. So you want to use annotations to generate the META-INF/<service> configuration file at compile time instead of writing this file manually.
That sounds like a good idea, but what would happen if you have two classes that implement the same service? Will the META-INF/<service> file be overwritten and will the order in which the classes are compiled determine which one is actually plugged in?
Originally posted by Jesper Young: That sounds like a good idea, but what would happen if you have two classes that implement the same service? Will the META-INF/<service> file be overwritten and will the order in which the classes are compiled determine which one is actually plugged in?
Actually the configuration file can contain more than two classes. It can contain as many as there are plugins out. The new Annotation is there to add each Plugin to that configuration file just for convenience.