Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Locating all classes implementing a given interface?

47 views
Skip to first unread message

Bas

unread,
Dec 2, 2007, 2:57:09 PM12/2/07
to
Hi,

my app allows third party code as plugins for certain behaviour. The
actual implementation to use can be specified using a string that
contains the classname. This works great.

However, I'd like the user to be able to specify the class name to use
using a popup menu.

The plugin is contained in a jar that is visible in the classpath.

Is it possible for my code to find all classes implementing my plugin
interface that are available at runtime? Iterating over a directory,
locate the jars and check those is not really what I want. Is this
sort of information dynamically available from the jre?

Thanks,

bas.

Message has been deleted

Mark Thornton

unread,
Dec 2, 2007, 3:12:50 PM12/2/07
to

The correct way to implement this type of feature is using
java.util.ServiceLoader (since Java 6). This has been the recommended
approach since at least Java 1.4, but ServiceLoader was added to make it
easier.

Mark Thornton

keke

unread,
Dec 3, 2007, 5:02:07 AM12/3/07
to
On Dec 3, 3:57 am, Bas <basschu...@gmail.com> wrote:
> Hi,
>
> my app allows third party code as plugins for certain behaviour. The
> actual implementation to use can be specified using a string that
> contains the classname. This works great.
I think there are two approaches:

1/ manually scan all classes available in your jar file
2/ specify your implementation somewhere, for example in your
manifest.mf file.

Cheers
K

0 new messages