Edw*_*ard 6 java compilation clojure gen-class leiningen
在我的Leiningen项目中:
(defproject com.stackoverflow.clojure/tests "0.1.0-SNAPSHOT"
:description "Tests of Clojure test-framework."
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[instaparse "1.3.4"]]
:aot [com.stackoverflow.clojure.testGenClass]
:source-paths ["src/main/clojure"]
:java-source-paths ["src/main/java"]
:test-paths ["src/test/clojure"]
:java-test-paths ["src/test/java"]
)
Run Code Online (Sandbox Code Playgroud)
我正在用gen-class生成Java类:
(ns com.stackoverflow.clojure.testGenClass
(:gen-class
:name com.stackoverflow.clojure.TestGenClass
:implements [com.stackoverflow.clojure.TestGenClassInterface]
:prefix "java-"))
(def ^:private pre "START: ")
(defn java-addToString [this text post]
(str pre text post))
Run Code Online (Sandbox Code Playgroud)
我想在Java中使用:
package com.stackoverflow.clojure;
public class TestGenClassTest {
private TestGenClassTest() {
}
public static void main(String[] args) {
TestGenClassInterface gc = new TestGenClass();
System.out.println(gc.addToString("Called from Java!", " :END"));
}
}
Run Code Online (Sandbox Code Playgroud)
启动lein compile会引发以下错误:
Compiling 4 source files to /home/eddy/workspace/TestSkripts/target/classes
/home/eddy/workspace/TestSkripts/src/main/java/com/stackoverflow/clojure/TestGenClassTest.java:9: error: cannot find symbol
TestGenClassInterface gc = new TestGenClass();
^
symbol: class TestGenClass
location: class TestGenClassTest
1 error
Run Code Online (Sandbox Code Playgroud)
在我看来,在编译Java代码(此处:)期间TestGenClassTest,该类不可用。我通常做的是
TestGenClass)lein compile(生成类文件)lein compile再次运行。我确定有更好的方法,可以使所有手动步骤重复。
让我再次向您推荐Polyglot (Clojure、Java) Projects With Leiningen,特别是这部分:Interleaving Compilation Steps。
默认情况下,Leiningen 正在执行javac,然后compile. 您还可以实现什么compile-> javac-> compile。