Whenever dynamically loading a class using the URLClassLoader I get a NoSuchMethodException when trying to execute a method with a custom data type as a parameter. It finds methods with standard types like String and int but not the custom type.
Loaded Class:
public void execute(ProcessingData data){
System.out.println("entered execute(ProcessingData data");
Calling Class:
URLClassLoader loader =
new URLClassLoader(new URL[] {new File(alg.getPath()).toURI().toURL()}, AlgorithmLoader.class.getClassLoader());
// Load class into memory
Class<?> algClass = Class.forName(className, true, loader);
logger.logInfo("Loaded class. Attempting to invoke execute(data) on aircraft: "+ data.getFlightData().getAircraftId());
Method processMethod = null;
try {
Object obj = algClass.newInstance();
processMethod = algClass.getDeclaredMethod("execute", ProcessingData.class);
processMethod.invoke(obj, data);
} catch (final NoSuchMethodException exception) {
logger.logInfo(exception.toString());
}
loader.close();
Aucun commentaire:
Enregistrer un commentaire