Last modified 6 years ago Last modified on 05/05/2011 09:49:04

Service discovering with annotation @ServiceProvider

Java offers a proper way for service discovering with its Meta-inf services specification, see this article for learning more about that.

Although this system is efficient, editing plain text files in META-INF/services/ could be a pain because they are not checked during the compilation. Netbeans offers a solution by introducing the annotation @ServiceProvider.

@ServiceProvider and maven 3

To be able to use this annotation and to ensure its process during compilation, you have to:

  • add the netbeans repository to your project:
  • add the lookup as dependency of your project:
  • then you can use the annotation in your code, and check that the files are correctly created in your jar during packaging phase:
    public class MyImplementation {
  • for retrieving registered services, you should use org.openide.util. Lookup utility class:



When I was using maven in version 2.x, I should specify the version of the compiler by putting something like that in your pom:

                <!-- default version doesn't support annotation processing
                required for @ServiceProvider -->