vendredi 20 décembre 2019

object is not an instance of declaring class on using java reflection

I am trying to load a class from a URL using java reflection and classLoader. The application is deployed on weblogic 12c server

        File f = new File("/a/abc");
        URL url = f.toURI().toURL();
        ClassLoader classLoader =  ClassLoader.getSystemClassLoader();
        Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
        method.setAccessible(true);
        method.invoke(classLoader, url);
        Class jobClass = classLoader.loadClass("com.test.abc");

However, I get the below error:

exception thrown:

java.lang.IllegalArgumentException: object is not an instance of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)

Please let me know what might be the issue here or if this is not the correct way to do it.





Aucun commentaire:

Enregistrer un commentaire