Return-Path: Delivered-To: apmail-cayenne-user-archive@www.apache.org Received: (qmail 15066 invoked from network); 4 Nov 2010 13:16:06 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 4 Nov 2010 13:16:06 -0000 Received: (qmail 31342 invoked by uid 500); 4 Nov 2010 13:16:38 -0000 Delivered-To: apmail-cayenne-user-archive@cayenne.apache.org Received: (qmail 31311 invoked by uid 500); 4 Nov 2010 13:16:35 -0000 Mailing-List: contact user-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cayenne.apache.org Delivered-To: mailing list user@cayenne.apache.org Received: (qmail 31299 invoked by uid 99); 4 Nov 2010 13:16:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Nov 2010 13:16:34 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [208.78.103.231] (HELO vorsha.objectstyle.org) (208.78.103.231) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 04 Nov 2010 13:16:27 +0000 Received: (qmail 24098 invoked from network); 4 Nov 2010 13:16:05 -0000 Received: from unknown (HELO ?IPv6:::1?) (127.0.0.1) by localhost with SMTP; 4 Nov 2010 13:16:05 -0000 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Apple Message framework v1081) Subject: Re: ClassLoader vs GroovyClassLoader From: Andrus Adamchik In-Reply-To: Date: Thu, 4 Nov 2010 09:16:04 -0400 Content-Transfer-Encoding: quoted-printable Message-Id: <02717DF7-2165-480B-945C-24C1FE4B66B7@objectstyle.org> References: To: user@cayenne.apache.org X-Mailer: Apple Mail (2.1081) X-Virus-Checked: Checked by ClamAV on apache.org Also be aware that most (all?) places in Cayenne 3.0.x were we load = classes dynamically would use a thread ClassLoader if available: Thread.currentThread().getContextClassLoader() so you can force your ClassLoader via = Thread.currentThread().setContextClassLoader(cl); Cayenne 3.1 uses a similar approach, and additionally allows to register = a custom service via DI. Andrus On Nov 3, 2010, at 3:57 PM, caden whitaker wrote: > 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: >=20 > ClassLoader parent =3D getClass().getClassLoader(); > GroovyClassLoader loader =3D new GroovyClassLoader(parent); > loader.parseClass(new > = File("C:\\tutorial\\src\\main\\java\\org\\example\\cayenne\\persistent\\St= ore.groovy")); >=20 > ResourceLocator rl =3D new ResourceLocator(); > rl.setClassLoader(loader); >=20 > Configuration c =3D new DefaultConfiguration("cayenne.xml", = rl); > c.addDomain(new DataDomain("default")); >=20 > On Wed, Nov 3, 2010 at 2:29 PM, caden whitaker = wrote: >=20 >> Hey all, hope you aren't tired of me yet >>=20 >> This in a nutshell is the problem: >> ClassLoader parent =3D getClass().getClassLoader(); >> GroovyClassLoader loader =3D new GroovyClassLoader(parent); >> loader.parseClass(new >> = File("C:\\tutorial\\src\\main\\java\\org\\example\\cayenne\\persistent\\St= ore.groovy")); >>=20 >> loader.loadClass("main.java.org.example.cayenne.persistent.Store"); >>=20 >> = System.out.println(Class.forName("main.java.org.example.cayenne.persistent= .Store", >> true, loader).toString()); >>=20 >> DataDomain dd =3D >> Configuration.getSharedConfiguration().getDomain(); >> ObjectContext context =3D dd.createDataContext(); >>=20 >> 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) >>=20 >> 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. >>=20 >>=20 >>=20