Calling Clojure From Java

While using Java APIs from Clojure is common due to Clojure’s embrace of the host platform, there are times when you’ll need to invoke Clojure directly from Java. For these cases, Clojure provides a Java API that can be used to directly access Clojure namespaces, vars, and functions.

The main entry point for the Clojure Java API is the clojure.java.api.Clojure class, which provides a few static methods for reading data, finding vars, and invoking unctions. With this handful of tools, you can invoke almost any aspect of Clojure.

For example, in a Java program, you can find the + function by using the var method of the Clojure class, which takes the namespace and name of a var and returns its value (in this case a ...

Get Programming Clojure, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.