1 Reply Latest reply on May 8, 2012 9:18 AM by sfcoy

    Invoke classes dynamically

    lucianom86

      Hi,

       

      I have system requirement and I'd like to see if it's possible to accomplish it with JBoss 7.

      Let's supose I have an application that needs to dynamically invoke classes that implement a specified interface at runtime.  So I'd have:

      application.war -> Contains the logic to dynamically invoke the classes

      interface.jar -> Both application.war and the implementations need to be aware of

      implementation-1.jar

      ...

      implementation-n.jar

       

      I'd like to deploy interface.jar and all its implementations as "shared libs" or "shared deploys", so application.war could "see" these classes and invoke them through reflection for instance.

       

      In the link https://community.jboss.org/wiki/ModuleCompatibleClassloadingGuide there's a session that seems to be what I need:

      Dynamic Classloading - Loading a class by name using a ClassLoader. This is typically used for pluggable architectures that discover some kind of extension. An example is an API framework that supports multiple implementations/providers (e.g. JAXP). It dynamically loads the provider by name using some kind of service discovery mechanism (a file in META-INF/services, a system property, etc). Another example is application server code which needs to operate against a deployment's classes. Since they are logically isolated, and may even be hot-deployed, static linking (imports) can not be used.

       

      But I wasn't able to find any relevant information about that.

       

      Does someone have any idea about how I could make that work?Maybe OSGI?

       

      Thanks in advance

      Luciano