Re: ClassLoader vs GroovyClassLoader

From: caden whitaker (caden.whitake..mail.com)
Date: Wed Nov 03 2010 - 19:57:51 UTC

  • Next message: Mark Fischer: "Re: Reengineer Database Schema not generating anything"

    Think I got it, at least doing this gave me a ton of new errors that make
    sense ;) please let me know if you think I'm on the wrong track:

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

                ResourceLocator rl = new ResourceLocator();
                rl.setClassLoader(loader);

                Configuration c = new DefaultConfiguration("cayenne.xml", rl);
                c.addDomain(new DataDomain("default"));

    On Wed, Nov 3, 2010 at 2:29 PM, caden whitaker <caden.whitake..mail.com>wrote:

    > 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.
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Nov 03 2010 - 19:58:22 UTC