2014-12-30 33 views
1

此代码不能与lein compile编译。重要的部分是gen-class-main函数。该代码使用JavaFX 8和Clojure 1.7,但这些仅仅是特定的。我的问题是关于AOT编译以及如何引用生成的类。引用来自AOT编译的Clojure生成的类?

(ns the.app 
    (:import 
    [javafx.application Application] 
    [javafx.scene Scene] 
    [javafx.scene.layout StackPane] 
    [javafx.stage Stage]) 
    (:gen-class 
    :name the.app.App 
    :extends javafx.application.Application 
    :main true)) 

(defn start 
    [^Application app 
    ^Stage stage 
    {:keys [width height title] :as opts}] 
    (let [root (StackPane.) 
     scene (Scene. root width height)] 
    (if title (.setTitle stage title)) 
    (.setScene stage scene) 
    (.show stage))) 

(defn -start 
    [app stage] 
    (start app stage {:title "App" :width 800 :height 600})) 

(defn -stop 
    [app] 
    (println "-stop")) 

(defn -main 
    [& args] 
    (Application/launch the.app.App args)) 

project.clj包含:

:dependencies [[org.clojure/clojure "1.7.0-alpha4"]] 
:aot [the.app] 
:main the.app 

的错误信息是:

Caused by: java.lang.ClassNotFoundException: the.app.App 

我本来以为编译将创造the.app.App。我怎样才能解决提到类compiled from AOT的问题?

回答

1

我发现,使用resolve作品(而不是直接引用类):

(defn -main 
    [& args] 
    (Application/launch (resolve 'the.app.App) args)) 

这意味着the.app.App没有当defn形式evaluated存在。该类只需要在运行时存在,这将在AOT编译后发生。