Clojure and Java source in the same NetBeans project

Has anyone successfully created a NetBeans project that integrates Clojure and a Java source?

I have projects in which the driver program (startup, gui, user prefs, etc.) is in Java, but the logic is in Clojure. At the moment, I am compiling Clojure code into a jar in one project and importing it as a library into a separate Java project. It would be convenient if the entire source could be combined in one NetBeans project.

Has anyone come up with a way to do this?

+5
source share
2 answers

One possible solution is to modify your Java NetBeans Ant script project (build.xml in the root directory) to use it.

NetBeans build.xml Ant , , (, ). - script, "-pre-compile", Clojure Ant "exec" ( JAR) .

, Ant ( Ant), build.xml.

+2

RT. Clojure script, :

try {
            RT.loadResourceScript("com/mydomain/app/clojure_scripts.clj"); // Initialize Clojure script processor with our script
        } catch (Exception e) {
            Util.logException(e, "Unable to run Clojure initialization script.");
        }

, Java, Clojure , :

/*
* Class to wrap Clojure scripts with Java friendly methods.
 */
public class Clojure {
    private static final String ns="com.mydomain.app";

    public static double calculate(final double size, final double otherVar) {
        Var report=RT.var(ns, "calculate");
        return (Double) report.invoke(size, otherVar);
    }
};
+1

All Articles