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.
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.