2014-12-30 32 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編譯後發生。