I am trying to get a class and call a method of that class. I can get the resource, from that i have a File and from that an absolute path to my class, but i can not get the actual class out of it so that i can call the method. How could i get the class from the resource/file/path? Class.forName gives---> "java.lang.ClassNotFoundException"
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath*:com/company/worker/module/*.class");
log.info("found RES:: " + Arrays.toString(resources));
Arrays.asList(resources).forEach(r -> {
try
{//////////////////////////Class.forName gives---> "java.lang.ClassNotFoundException"///////
Method handleRequest = Class.forName(r.getFile().getAbsolutePath()).getDeclaredMethod("handleRequest",
Parameter.class, java.lang.String.class);
handleRequest.invoke(searchParameter, myType);
}
catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException | NoSuchMethodException
| ClassNotFoundException | IOException e)
{
e.printStackTrace();
}
});