[jboss-user] [Beginners Corner] - dynamically load classes within app on JBOSS

tuezney do-not-reply at jboss.com
Mon Sep 15 09:37:02 EDT 2008


Hello,

I am using jboss 4.2.3.GA and am trying to load a class dynamically as shown in your example on :

http://wiki.jboss.org/wiki/HowCanIDynamicallyLoadClassesWithinAnMBean


this is a piece of my code :

// Load the class :
logger.debug("getting classLoader ");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
logger.debug("Loading class " + className);
Class  deployableApplicationClass =  classLoader.loadClass(className);
logger.debug("Instantiating Object");
Object deployableApplicationObject = deployableApplicationClass.newInstance();


           
// implemented interfaces
logger.debug("listing interfaces: ");
for (Class clt : deployableApplicationObject.getClass().getInterfaces()){
    logger.debug("list interfaces deployableApplicationObject implements: " + clt.getName());
}

logger.debug("casting");
app = (DeployableApplication)deployableApplicationObject;


It always fails on the cast : app = (DeployableApplication)deployableApplicationObject;

with a ClassCastException

this is the server log :

2008-09-15 12:52:39,932 DEBUG [be.kmi_irm.labo.web.LoadAppsController] getting classLoader
2008-09-15 12:52:39,932 DEBUG [be.kmi_irm.labo.web.LoadAppsController] Loading class be.kmi_irm.labo.imaging.medriasclient.MedriasClient
2008-09-15 12:52:39,946 DEBUG [be.kmi_irm.labo.web.LoadAppsController]
Instantiating Object
2008-09-15 12:52:39,979 DEBUG [be.kmi_irm.labo.web.LoadAppsController] listing interfaces:
2008-09-15 12:52:39,980 DEBUG [be.kmi_irm.labo.web.LoadAppsController] list interfaces deployableApplicationObject implements: be.kmi_irm.labo.web.app.DeployableApplication
2008-09-15 12:52:39,980 DEBUG [be.kmi_irm.labo.web.LoadAppsController] casting
2008-09-15 12:52:39,980 DEBUG [be.kmi_irm.labo.web.LoadAppsController] ClassCastException : be.kmi_irm.labo.imaging.medriasclient.MedriasClient cannot be cast to be.kmi_irm.labo.web.app.DeployableApplication
2008-09-15 12:52:39,981 ERROR [STDERR] java.lang.ClassCastException: be.kmi_irm.labo.imaging.medriasclient.MedriasClient cannot be cast to be.kmi_irm.labo.web.app.DeployableApplication



While the loaded class implements the interface "DeployableApplication"


Could you tell me what is going wrong.


Kind regards,

Alain

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4176510#4176510

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4176510



More information about the jboss-user mailing list