Which Way Should I Use To Register an Object in the Default Lookup?

Apache NetBeans Wiki Index

Note: These pages are being reviewed.

There are two ways to put something in the default Lookup:

What When to Use It How

Use the @ServiceProvider annotation

Most of the time, unless you are building with Maven. This annotation relies on NetBeans' build infrastructure to generate flat files in META-INF/services described below, at compile time.

Annotate your file with @ServiceProvider(service=Something.class)

Put an .instance file in your module layer in Services/Hidden

Rarely - useful if you are making services available dynamically on the fly, for example when dynamically changing layer contents, or when specialized registration metadata or factory methods are needed

Declare a .instance file, a .settings file or similar, or a .shadow file in your module’s layer.xml file