简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM