Let's say we want to use the Derby database. All we need to do is include the derby.jar file in our classpath, and the driver will automatically be available to us. There is no more need to use Class.forName().After a brief explanation on how to this functions, Heinz then moves on to implement his own service. If you follow the steps laid out in the newsletter you’ll end up with a music service. The newsletter ends with a warning on the use of ‘*’ in the classpath. As if getting the classpath straight wasn’t difficult enough, with this wildcard we now have new ways of not getting what we expected.
Dr. Heinz Kabutz explains how to use the Mustang ServiceLoader in the latest edition of his Java Specialist newsletter. In the newsletter he demonstrates how the new ServiceLoader works. The ServiceLoader replaces the Class.forName() mechanism that has been used since the 1.1 to load JDBC drivers. With the 6.0, we no longer have to specifically load the JDBC drivers.
- Posted by: Kirk Pepperdine
- Posted on: February 12 2007 10:01 EST
Mustang's ServiceLoader is really the good'old com.sun.Service, refactored into a nice user-accessible class. I use the same technique for my application plugins needs. See for example how easy it is to extend my J2EE monitoring utility: create the jar file, drop it somewhere in the classpath, done. No hair-splitting configuration file to edit! ________ MessAdmin, J2EE monitoring made easy