I\'m thinking about start using (not playing with) Clojure. Are there any useful guides? I\'m not asking about lein, javac or any other \'small\' manual tools. I need to kno
You could also try the framework "Funky". It will completly seperate you Clojure and Java code . Just have a look at https://github.com/windler/Funky
Despite your tone about leiningen, I recommend looking at it. Leiningen supports Java compilation, so combining java and clojure sources in one project isn't a problem.
The Counterclockwise plugin, the clojure plugin for Eclipse, can work with leiningen project files (project.clj). So within Eclipse you have dependency management and java compilation all handled for you by defining the right things in project.clj, without the need to install leiningen separately or execute commands from the command line.
In the project.clj set :java-source-paths, like for example:
:java-source-paths ["src/main/java"]
In package src/main/java put a class Foo:
package main.java;
public class Foo {
public static final String value = "Michiel";
}
Somewhere in a clojure source file define this function and "Michiel" will be printed when it is called:
(defn foo
"I don't do a whole lot."
[]
(println (main.Foo/value)))
Further reading:
I have a fully working production setup with Eclipse, Maven and Clojure that is working very nicely at the moment. Hopefully it is helpful as an example of a good polyglot setup within a Java IDE.
I don't use leiningen - Nothing against lein at all - it's very nice and ideal in a pure Clojure/CLI world. But I've found that pure Maven is nicer to work with in a polyglot Java+Clojure environment with an IDE since the tool integration is so much better. Also from an ecosystem / audience / community perspective if you want people from the Java world to be able to build your source you are going to cause a lot less confusion if you just use Maven directly.
Here is my setup:
In terms of actually how I manage / set up the project itself:
src/main/java
and src/main/clojure
.clj
files get bundled in any jars and can be loaded / run dynamically at runtime.public static void main(...)
as usual, but call quite quickly into the Clojure code. See this blog post on calling Clojure from Java.Finally some coding tips for polyglot Java+Clojure
clojure.lang.IFn
for example. This way your Java objects can act as first class functions in Clojure code.Here's an example project that mixes Java and Clojure source:
I also wrote a small library (clojure-utils) that includes some example code for calling Clojure from Java, which you may find useful.