cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From caden whitaker <caden.whita...@gmail.com>
Subject ClassLoader vs GroovyClassLoader
Date Wed, 03 Nov 2010 19:29:38 GMT
Hey all, hope you aren't tired of me yet

This in a nutshell is the problem:
            ClassLoader parent = getClass().getClassLoader();
            GroovyClassLoader loader = new GroovyClassLoader(parent);
            loader.parseClass(new
File("C:\\tutorial\\src\\main\\java\\org\\example\\cayenne\\persistent\\Store.groovy"));

loader.loadClass("main.java.org.example.cayenne.persistent.Store");

System.out.println(Class.forName("main.java.org.example.cayenne.persistent.Store",
true, loader).toString());

            DataDomain dd =
Configuration.getSharedConfiguration().getDomain();
            ObjectContext context = dd.createDataContext();

Error:
java.lang.ClassNotFoundException: class
main.java.org.example.cayenne.persistent.Store
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at
main.java.org.example.cayenne.ut.CayenneUnitTest.testBuild(CayenneUnitTest.java:128)

At this point the "Store" object (which is compiled at runtime through
Groovy) does not exist in any context that teh DataContext can find it, the
DataContext is looking for it in Class.forName, but that is looking in the
default ClassLoader. This "Store" object does not exist in that context, it
is in its own ClassLoader (GroovyClassLoader). So how do I tell the system
to load the object from this GroovyClassLoader?? I know this is the issue
because if I take that Store object, make it a Java class, compile it, and
run the same test it works fine.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message