Cannot load clojure classes from Jar files outside classpath using URLClassLoader
Description
Environment
None
Activity

import August 24, 2010 at 9:18 PM
import
August 24, 2010 at 9:18 PM
Comment made by: importer
stu said: Clojure's base loader uses the thread context loader so long as use-context-classloader is true (the default). Make sure context class loader is set, and then set the thread context class loader to be the loader you have created by calling:
Do this before using the loader to load classes.
Cheers,
Stu

import August 24, 2010 at 9:18 PM
import
August 24, 2010 at 9:18 PM
Comment made by: importer
Converted from http://www.assembla.com/spaces/clojure/tickets/260
Attachments:
loader.tar.gz - https://www.assembla.com/spaces/clojure/documents/ayyZTifAyr34QPeJe5aVNr/download/ayyZTifAyr34QPeJe5aVNr
Declined
Details
Created February 10, 2010 at 1:08 AM
Updated August 24, 2010 at 9:18 PM
Resolved August 24, 2010 at 9:18 PM
It is not possible to use URLClassLoader to load a class from a jar file if the jar is outside the classpath. It seems that RT.load tries to search for *.clj file within the classpath and doesn't respect the URLClassLoader and then fails with:
Exception in thread "main" java.lang.ExceptionInInitializerError
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at Loader.main(Loader.java:17)
Caused by: java.io.FileNotFoundException: Could not locate net/experimentalworks/Foo__init.class or net/experimentalworks/Foo.clj on classpath:
at clojure.lang.RT.load(RT.java:402)
at clojure.lang.RT.load(RT.java:371)
at clojure.core$load_6449$fn_6458.invoke(core.clj:4171)
at clojure.core$load__6449.doInvoke(core.clj:4170)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.lang.Var.invoke(Var.java:359)
at net.experimentalworks.Foo.<clinit>(Unknown Source)
... 7 more
The attached .tar.gz contains a sample jar file and the clojure file that was used to generate the class files as well as the sample loader. Java oder Scala written classes can be loaded without any problems. For sure the I put the clojure runtime into the classpath but not the loadme-clojure.jar