Document setting *use-context-classloader* to false from Java
*use-context-classloader* seems especially useful to set to false in a Java environment where security or other restrictions prevent using other classloaders. But the need to set it very early (i.e. before clojure.core is loaded) makes it challenging to do from Java. If this is supported, can it be documented somewhere?
Yeah, it’s a strange environment. The Clojure classes are available from the class classloader (i.e. MyPluginClass.class.getClassLoader() ). I tried to do what you’re suggesting and it does seem to fix the problem, except I’m not allowed to do that in this environment. The classloader getters & setters are restricted.
Basically I need a way to tell Clojure to not do anything with custom classloaders, but instead just load up its classes using the default loader.
It seemed like a prefect use case for setting *use-context-classloader* to false . But I can’t figure out how to do that in an environment where I can’t load / use set! yet.
I'm not sure this is possible right now, but I'm not sure I fully understand the environment. If the Clojure classes are not available via the context classloader, where are they available from? Maybe alternatively you could properly set the context classloader to that before loading Clojure:
I’m attempting to invoke it via the official Java API, but this issue stops me before I get that far. This is in a Sonarqube plugin where the system loading the plugin is providing a fairly restrictive classloader environment in order to sandbox plugins. In this environment if Clojure attempts to use the context classloader, it won’t be able to find any of its own classes. This manifests itself as a class not found error for clojure.core. I think (but have been unable to confirm) that setting *use-context-classloader* to false before Clojure attempts to load even clojure.core might fix this.
Can you share more about how you are invoking Clojure from Java?