How to Use Apache Commons Discovery

1) Create the file:


import static java.lang.System.out;

public final class CommonsSample {

  public static void main(final String[] args) {

    try {
      final DiscoverClass discoverer = new DiscoverClass();

      final Class cls = discoverer.find(HelloWorldIfc.class);

      final HelloWorldIfc helloWorld = (HelloWorldIfc)cls.newInstance();


    catch (final IllegalAccessException e) {

    catch (final InstantiationException e) {



2) Create the file:

public interface HelloWorldIfc {
  String sayHello();

3) Create the file:

public final class HelloWorldImpl implements HelloWorldIfc {

  public String sayHello() {
    return "Hello World!";


4) Compile the, and files.

5) Set the HelloWorldIfc system property to HelloWorldImpl.

6) Launch the CommonsSample class.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.