In order to be able to use the class defined in Example.java
, you have to compile it and place the resulting class file on the classpath.
If this Java file is a helper in a Clojure project, you can use Leiningen to automate the process:
(defproject foo "1.2.3-SNAPSHOT"
; ...
:java-source-paths ["src/main/java"]
)
Assuming Example.java
lives in a subdirectory of src/main/java
, Leiningen will compile it and include it on the classpath when you use it to start a REPL or prepare a jar of your project. (There's also :javac-options
for specifying options to be passed to the Java compiler as a vector of strings.)
If your Java source tree is more extensive and independent of the Clojure side of the project, it might make more sense to package it as a separate Java project instead. The Clojure side would then use the Java project as a dependency.