“线程中的异常”;“主要”;java.lang.ExceptionInInitializerError(Clojure)
我正在尝试以.jar和.war格式部署Clojure应用程序。到目前为止,我已经成功地部署了一个.jar;我在研究战争。该应用程序只是一个测试应用程序,旨在演示Clojure和JavaFX的一些功能。我打算通过AWS Elastic Beanstalk将其部署到我刚刚开始建立的网站上。目前,该应用程序仅显示一组模糊的圆圈,在600x600舞台上移动40秒。然而,即使应用程序在这40秒内成功运行,它总是在这40秒动画之后突然终止。我的project.clj文件如下所示:“线程中的异常”;“主要”;java.lang.ExceptionInInitializerError(Clojure),java,exception,clojure,javafx,main,Java,Exception,Clojure,Javafx,Main,我正在尝试以.jar和.war格式部署Clojure应用程序。到目前为止,我已经成功地部署了一个.jar;我在研究战争。该应用程序只是一个测试应用程序,旨在演示Clojure和JavaFX的一些功能。我打算通过AWS Elastic Beanstalk将其部署到我刚刚开始建立的网站上。目前,该应用程序仅显示一组模糊的圆圈,在600x600舞台上移动40秒。然而,即使应用程序在这40秒内成功运行,它总是在这40秒动画之后突然终止。我的project.clj文件如下所示: (defproject c
(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线程的工作方式有关。当动画停止运行时,可能会出现某种超时。相比之下,当我在project.clj
中注释掉主clojurefx.arg.splashpage
和时没有超时,只需手动将splashpage.clj
文件中的代码复制、粘贴和评估到REPL中即可。另外,当我将JavaFX对象初始化和显示的代码放在函数中时,比如说,(init stage)
,这样在显式调用函数之前不会在运行时计算代码,“超时”会在JVM启动和调用(-main)
函数后立即开始
想法?我意识到认识Clojure的人和认识JavaFX8的人的交集非常小
其他信息:
我想还有一个相关的问题。现在,当我尝试部署.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时(无论是单机版还是非单机版),OSX都会说“文件无法启动”。此外,实际创建.jar的点是动画停止或退出显示动画的main
应用程序(JVM)。答案是,对于要导入的某些JavaFX类,需要调用以下命令:
(defonce force toolkit init(javafx.embed.swing.JFXPanel.))
defonce
用于确保工具包没有以某种方式重新初始化
即使在导入任何JavaFX类之前,也可能建议声明此错误。ExceptionInInitializeError在静态块失败时发生。您可以打开关闭jar中的main,反编译main类,然后查看静态块是否引用了不存在的内容。什么是tmln
?我在列表中的任何地方都没有看到它的定义?这只是播放动画的时间吗?此外,如果没有堆栈跟踪,很难猜测哪些代码失败。堆栈跟踪中有没有提到您的代码,或者是所有其他lib,比如JavaFX?@NathanDavis-对不起,tmln是一个时间线对象。如果您愿意,我可以发布一个完整的堆栈跟踪,但是除了Java和JavaFX libs之外,我没有提到任何东西。@GV-很好的建议。我不熟悉反编译JAR,但我确信网上有一些很好的教程。我会告诉你事情的进展。