jeudi 22 septembre 2016

Can't find Class with Class.forName() but it exists

I have a program in which I am generating classes at runtime (included only variable and associated getters and setters methods). Later I want to fill the classes.

To get the class - I know its Name, but its not in the classpath - I tried .forName() but I always get a ClassNotFoundException.

Here is my example:

Exception in thread "main" java.lang.ClassNotFoundException: com.test.wam.business.wsobjects.Testclass
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at gui.Application.main(Application.java:94)

And the code:

URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader(); DynamicURLClassLoader dynamicURLClassLoader = new DynamicURLClassLoader(urlClassLoader); dynamicURLClassLoader.addURL(new URL("http://fileC:\dev\Eclipse_was\guitest\generated"));

    Class c = Class.forName("com.test.wam.business.wsobjects.Testclass");

    Object classInstance = c.newInstance();

The full qualified Name to the file (created with eclipse -> copy full qualified Name)

/guitest/generated/com/test/wam/business/wsobjects/Testclass.java

What is wrong here?





Aucun commentaire:

Enregistrer un commentaire