我正在尝试以.jar和.war格式部署Clojure应用程序。到目前为止,我已经成功地部署了一个.jar;我正在开发.war。该应用程序只是一个测试应用程序,目的是演示Clojure和JavaFX的一些功能。我的意思是通过AWS弹性豆茎部署到一个网站,我才刚刚开始建立。目前,这款应用程序只显示了一堆模糊的圆圈,在600x600舞台上移动了40秒。然而,即使应用程序成功运行了40秒,它总是在这40秒的动画之后突然终止。我的project.clj文件如下所示:
(defproject clojurefx/arg "0.0.10-SNAPSHOT"
:description "Helper functions and probably a wrapper to simplify usage of JavaFX in Clojure.
This is meant to be used with Java 8.
..."
:url "https://www.github.com/zilti/clojurefx" ; my project is essentially forked from this project
:lein-release {:deploy-via :clojars}
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]]
:plugins [[lein-marginalia "0.7.1"]
...]
:profiles {:dev {:dependencies [[midje "1.6-beta1"]]}}
:main clojurefx.arg.splashpage
:aot [clojurefx.arg.splashpage])这是-main函数存在的地方:
(ns clojurefx.arg.splashpage
(:require
[clojure.reflect :as clj-r]
[clojure.stacktrace :as stacktrace]
[clojurefx.arg.core :as core]
[clojurefx.arg.core :refer [deffx]]
...)
(:import
(javafx.scene.text Font FontPosture FontWeight Text)
...)
(:gen-class))
(defn -main [& args]
(println "Up and running! The arguments supplied were: " args))
;=====JavaFX visual objects initialized and displayed with the code below=====
;-----Root-----
(deffx rt group)
;-----Scene/Window-----
(deffx scn scene
:width 600
:height 600
:root rt
:fill (. Color BLACK))
;-----Stage/Window-surround-----
(deffx stg stage
:title "Colorful Circles"
...
(dofx (.show stg)) ; shows the JavaFX window with the circle animation
(dofx (.play tmln)) ; play 40s of animation正如我说过的,动画播放了40秒,但是我得到了下面的例外:
-> Exception in thread "main" java.lang.ExceptionInInitializerError
-> at clojure.main.main(main.java:37)
... ; a long list of traced errors
-> Caused by: java.lang.IllegalStateException: Toolkit not initialized
... ; a long list of traced errors
-> Exception in thread "Thread-4" clojure.lang.ExceptionInfo: Subprocess failed {:exit-code 1}
... ; a long list of traced errors
-> at java.lang.Thread.run(Thread.java:724)我认为这可能与JavaFX线程的工作方式有关。当动画停止运行时,可能会有某种超时。相比之下,当我在main clojurefx.arg.splashpage和:aot [clojurefx.arg.splashpage])中注释project.clj并手动复制、粘贴和计算从splashpage.clj文件到REPL中的代码时,没有超时。另外,当我将用于JavaFX对象初始化的代码放在函数中显示时,比方说,在函数被显式调用之前,在运行时不会对代码进行计算,“超时值”将在JVM启动和调用(-main)函数之后立即开始。
有什么想法?我意识到,一组熟悉JavaFX 8的人和一组熟悉Clojure的人的交集非常小.
更多信息:
我还有另外一个相关的问题。现在,当我尝试部署一个.jar文件时,该文件将成功地创建,如下所示:
Alexanders-MacBook-Pro:cljfx-arg alexandergunnarson$ lein uberjar
Compiling clojurefx.arg.splashpage
Created /Users/alexandergunnarson/.lein/cljfx-arg/target/arg-0.0.10-SNAPSHOT.jar
Created /Users/alexandergunnarson/.lein/cljfx-arg/target/arg-0.0.10-SNAPSHOT-standalone.jar但是当我在我的Mac上运行.jar (不管是独立的还是非独立的)时,OS说“文件不能启动。”另外,.jar的实际创建点是动画停止或退出显示动画( JVM)的main应用程序的点。
发布于 2014-08-24 02:54:30
对此的回答是,要导入某些JavaFX类,需要调用以下内容:
(defonce force-toolkit-init (javafx.embed.swing.JFXPanel.))
defonce用于确保工具包不会以某种方式重新初始化。
在导入任何JavaFX类之前声明这一点可能是明智的。
https://stackoverflow.com/questions/19966572
复制相似问题