Share your thoughts in the 2024 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in Clojure by

I'm trying to write a user-defined function for KSQL in Clojure. KSQL wants you to give it an uberjar with an annotated java class. I've tried this with both gen-class and a hand-authored java file that interops to Clojure. In both cases, the uberjar gets loaded fine, and my class annotations are detected via reflection. But I get exceptions like "java.lang.ExceptionInInitializerError" and "java.lang.NoClassDefFoundError: Could not initialize class clojure.java.api.Clojure" as soon as anything to do with clojure is executed, like Clojure.var("clojure.core", "require") Feels like I must be missing something about how the uberjar needs to be built. Or perhaps this is a classloader issue. KSQL apparently does some kind of classpath isolation to keep user-defined functions from stepping on each other.

1 Answer

0 votes
by
selected by
 
Best answer

Either the jar is invalid for some reason or it's something classloader-related - the NoClassDefFoundError is a pretty clear indication that the thread context classloader can't see that class.

To check the jar you can do jar -tf theuber.jar | grep Clojure - you should see clojure/java/api/Clojure.class if it's in there.

by
It was the classloader. Forcing use of the thread context classloader got it working. Thanks.
...