1
votes

Begin Edit: Primarily I want my Clojure program to use a Java class.

I've also gotten some good advice on going back to lein from cake, because they're merging.

If anyone reading this can recommend a book more for setting up a Java/Clojure build environment than learning Java, I would appreciate it. End Edit:

Although I can read Java code, I am not a Java programmer. I am building Clojure main programs successfully using cake, and need to create a Java class that becomes part of my Clojure main. I cannot figure out how to incorporate the MyClass.class into the Clojure build.

First here is my project.clj followed by a few lines of the application .clj file.

(defproject ba1-app "0.0.1-SNAPSHOT"
  :description "TODO: add summary of your project"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [org.clojure/tools.cli "0.1.0"]]
   :main ba2-app)

(ns ba2-app
    (:gen-class)
    (:use [clojure.string :only [split]]
          [clojure.string :only [join]]))

(def^:dynamic avail-trans [\W \D])
(def^:dynamic acct-types [[\C 0.02][\S 0.04] [\M 0.06]])
.
.
.

1) Should the .java file go into the same directory as the .clj application module?

2) What would the build instructions be?

Thanks.

1

1 Answers

2
votes

It is not exactly clear what you want to do. I assume that you want to compile java class and use in your clojure sources. In this case you don't have to do something special. Put your java classes where you want (say, dir '/project_dir/src') and add

:java-source-path "src"

to your project.clj file. In this case java classes will be compiled along with clojure files, and their package hierarchy root will start from this directory you've chosen. You can now use these classes like you woul use any other classes - :import clause in (ns ...) form or direct (import ...).

UPD. It could also be mentioned that you can freely mix your java source directory with your clojure sources, so you can have project.clj options :source-path and :java-source-part set to the same value, "src" in this example.