Search code examples
clojure

Get (or write) class files for the classes in the DynamicClassLoader


Is there any way to find/write the class files for the classes in the DynamicClassLoader?

  (let [f #(+ 1 %)
        cls (class f)
        cl (.getClassLoader cls)]
    
    (println (.getName cls)) ; => my.project.namespace$eval123$f__4321

    ;; Do something here to get a path to a class file
    ;; .../my/project/namespace/eval123$f__4321.class

    )

Solution

  • After browsing the Clojure source code I found a compiler var that does exactly what I want. I don't know if I would recommend this approach, but it was been working well for me so far.

    (.bindRoot Compiler/COMPILE_FILES true)
    

    This will write .class files to the path under *compile-path*.