Creating Extensible Applications
Do you know about the
ServiceLoader api in Java SE 6? It's another of those many improvements to the Java platform that you may have overlooked. This particular API helps you create extensible applications -- applications that let you add services and functionality without modifying the original application. Nice, right?
One of the most popular ways to add new libraries to your apps is to stick their JAR file on the classpath. You already knew that. But did you also know that your application can use that functionality even if it doesn't know the specific class names in the JAR. The
ServiceLoader API makes this possible by helping you define a service provider interface. You define the interface in your application, but you implement the interface in files that you can add to your application later.
The NetBeans Platform provides similar and improved support for extensible services. It's
Lookup API provides everything that's in
ServiceLoader and more. Plus, you can use the NetBeans APIs on earlier versions of the JDK -- before Java SE 6.
I've put together my notes on this subject and created a full-length article. You can read Creating Extensible Applications with the Java Platform over on the Sun's Developer Network for Java.
Let me know if this helps you. I always appreciate your feedback!