Fork me on GitHub

Am I correct in thinking that if I load Clojure from Java, by loading a class which requires RT, then clojure.core will always be loaded from the TCCL via RT.baseLoader()?


I can’t set Compiler.LOADER or RT.USE_CONTEXT_CLASSLOADER, since manipulation either of them will cause RT to be loaded, which will try to use the TCCL to load clojure.core.


in whatever version of clojure I have checked out it looks like RT.USE_CONTEXT_CLASSLOADER defaults to true


Yeah, it does.


I can’t see any other way to influence the classloader that’s used.


Or to control the initial values of those vars via a system property or whatever.


could you x = getContextClassLoader() try { setContextClassLoader(null); loadClojure(); } finally { setContextClassLoader(x); } or whatever?


I can’t do that unfortunately. I’m trying to use Clojure-compiled classes in IntelliJ. The classes are instantiated by IntelliJ, and I can’t set the TCCL when that happens. If a class that IntelliJ wants is compiled by Clojure and thus has an implicit RT dependency, and Clojure hasn’t been loaded yet, then I get an ExceptionInInitializerException and the class can’t load.


I suppose this is an effort to replace a java stub class with one generated by clojure, so suggesting a java stub class isn't going to help


I can do that, yes, it’s more or less what I’m doing at the moment. It’s fairly awful though, I basically end up writing manual gen-class-like classes in Java.


And I have to write a lot of them. I’m running a fork of Clojure, so I think I’ll just modify baseLoader()


you could do a custom gen-class macro too (but I bet the baseloader mod is less work)


Yes, no doubt.


on the other end of the work spectrum you could patch the class file's static initializer to do the tccl dance


Right, or modify my fork to change how works. But that’s still going to be a nasty hack, and more invasive than just fixing baseLoader() I think.