简体   繁体   中英

Clojure custom Java Interop

I'm trying to find the best documentation and information on integrating custom Java files into a Clojure project. I've reviewed the project Enlight and see that the files are all .java files under the /src/main/java directory. Unfortunately it doesn't use Leiningen (what I'm using) so I can't see how it is called together the java files.

Suppose I want to use a big Java project from Clojure, like MALLET , which is abstracted into oblivion that a standard, major, main entry point like public static void main () cannot be found. Do I just dump every .java file into my classpath and hope for the best?

To include your own .java files in Leiningen project:

(defproject my-project "0.0.1-SNAPSHOT"
  ; ...
  :java-source-paths ["src/main/java" "src_other/java"]) ; It's up to you how to structure paths

In this setup your .java files compilation will be managed by Leiningen.

To include existing Java project which is available in some of Maven repositories, just add dependency. For MALLET it will look like:

(defproject my-project "0.0.1-SNAPSHOT"
  ; ...
  :dependencies [[cc.mallet/mallet "2.0.7"]])

Finally, if the goal is to include private jar file - the best option is to create local Maven repository.

In all of these cases you will be able to do normal Java <-> Clojure interop.

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