Calling Clojure Functions from Java

Mixing Clojure functions and Java methods usually happens when pure Clojure applications need to interact with Java libraries. However, sometimes you have Clojure functions receiving events from a Java program. This is often the case when you have a Java program with a JavaFX, Java Swing, or Java AWT GUI, but you want all the controller logic written in Clojure. It certainly is  possible to write Clojure code calling Java libraries to create a decent UI, but doing so would be clunky at best.

It is also possible that you have a legacy Java application that you want to write Clojure plugins for. This is easily accomplished by calling Clojure functions from any appropriate place in the Java code. You can call directly into uncompiled Clojure scripts. To call Clojure scripts, you just need to know the right classes for loading your code.

Continue reading “Calling Clojure Functions from Java”