Avi Chapman
Avi Chapman

Reputation: 37

Finding all Java beans that implement a particular interface

I've been trying to write an EJB that scans the JBoss server that it is running on and comes up with a list of all available classes that implement a particular interface. This is easy in C# and I've seen a few examples in Java. However, the Java examples are designed for use in an Application container. I need something that works on JBoss.

I've tried playing with enumerating all available EJBs and haven't been able to make it work. Can anyone help me with this?

Thanks, Avi

Upvotes: 1

Views: 1107

Answers (3)

bruno.zambiazi
bruno.zambiazi

Reputation: 1482

If you want to get all implementations of some interface, you can use @Any annotation and Instance class.

Take a look at this: https://goo.gl/Kbn0bP

Upvotes: 0

Nayan Wadekar
Nayan Wadekar

Reputation: 11602

You can use JMX to connect with JBoss server & can get all beans that are deployed on the server. Then as you can use reflection to verify further, implementation for particular interface etc.

Link : How do I find out what port my jboss server is listening on programmatically using JBoss 4.2.3? connection with JBoss using JMX. Then base on specific attributes, you can fetch information from the server.

Upvotes: 1

Peter Lawrey
Peter Lawrey

Reputation: 533472

You might find this library useful http://code.google.com/p/reflections/

Using Reflections you can query your metadata such as:

  • get all subtypes of some type
  • get all types/methods/fields annotated with some annotation, w/o annotation parameters matching
  • get all resources matching matching a regular expression

Upvotes: 1

Related Questions