Search code examples
javadynamicclojure

How to use clojure files dynamically?


I want use java code to run some clojure files dynamically which are in some zip files.

If the clj.p1.core.clj is on the class path, it can runs correctly.

require.invoke(Clojure.read("clj.p1.core"));

How to make it dynamically?That is, put clj.p1.core.clj in the a1.zip (maybe some files), the java program could select the zip and then run it?


Solution

  • Probably, you should unzip those files first and then specify a *.clj file when invoking Compile class; take a look at its sources.

    What would be much better in your case is to compile a Java class from Clojure sources first and then load that class in Java as well. Just add a specific step into your build process that cares of it. In that case, your Java code will look much simpler and wont' waste time on loading Clojure code dynamically.

    Creating a Java file would be easy; just wrap Clojure sources with additional namespace with gen-class declaration. Move its output into your Java project or specify classpath properly. See gen-class page for more examples.