fx-clj icon indicating copy to clipboard operation
fx-clj copied to clipboard

uberjar and compile

Open ghost opened this issue 10 years ago • 11 comments
trafficstars

Anyone else has problems with uberjar and compile? It just won't complete. I have to use a Runner class as a workaround and run my clojure code without AOT which results in long startup times when I run the jar file :(.

public class Runner {

  public static void main(String[] args) {
    clojure.lang.IFn require = clojure.java.api.Clojure.var("clojure.core", "require");
    require.invoke(clojure.lang.Symbol.intern("my-gui.core"));
    clojure.lang.IFn show = clojure.lang.RT.var("my-gui.core", "show");
    show.invoke();
  }
}
; ------------------------------------------------------
(ns my-gui.core
  (:require [fx-clj.core :as fx]))

(defn view []
  (fx/compile-fx ...........))

(defn show []
  (fx/sandbox #'view))
; ------------------------------------------------------
(defproject
  ... NO AOT
  :main Runner
  ...)

ghost avatar Mar 28 '15 17:03 ghost

I also encountered this issue. According to this discussion (https://groups.google.com/forum/m/#!topic/leiningen/s9CBKp832YE), initializations are executed while AOT. I'm not sure about that, I think it's a problem of fx-clj. Maybe some patches will be needed.

KPCCoiL avatar Sep 16 '15 07:09 KPCCoiL

Can anyone post a stack trace? On Wed, Sep 16, 2015 at 3:56 AM KPCCoiL [email protected] wrote:

I also encountered this issue. According to this discussion ( https://groups.google.com/forum/m/#!topic/leiningen/s9CBKp832YE), initializations are executed while AOT. I'm not sure about that, I think it's a problem of fx-clj. Maybe some patches will be needed.

— Reply to this email directly or view it on GitHub https://github.com/aaronc/fx-clj/issues/5#issuecomment-140660040.

aaronc avatar Sep 16 '15 14:09 aaronc

I don't know how to display the stack trace, but I could cause the problem with this tiny project:

project.clj:

(defproject fx-clj-test "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.8.0-alpha2"]
                 [fx-clj "0.2.0-alpha1"]]
  :main ^:skip-aot fx-clj-test.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

src/fx_clj_test/core.clj:

(ns fx-clj-test.core
  (:require [fx-clj.core :as fx])
  (:gen-class))

(defn make-view []
  (fx/button "Hello!"))

(defn -main [& args]
  (fx/sandbox #'make-view))

When I executed lein uberjar in this project, "Compiling fx-clj-test.core" appeared and it freezed. In other hand, lein run works fine.

KPCCoiL avatar Sep 16 '15 14:09 KPCCoiL

I was able to create an uberjar but that was a while ago and it took some tweaking. My issue was related to a dependency that was causing problems, but I've since replaced that dependency. Unfortunately, I haven't been working with this code base for a while and don't really have a lot of time right now. Maybe someone else can provide some insight?

On Wed, Sep 16, 2015 at 10:23 AM, KPCCoiL [email protected] wrote:

I don't know how to display the stack trace, but I could cause the problem with this tiny project:

project.clj:

(defproject fx-clj-test "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.8.0-alpha2"] [fx-clj "0.2.0-alpha1"]] :main ^:skip-aot fx-clj-test.core :target-path "target/%s" :profiles {:uberjar {:aot :all}})

src/fx_clj_test/core.clj:

(ns fx-clj-test.core (:require [fx-clj.core :as fx]) (:gen-class))

(defn make-view )

(defn -main [& args](fx/sandbox #'make-view))

When I executed lein uberjar in this project, "Compiling fx-clj-test.core" appeared and it freezed. In other hand, lein run works fine.

— Reply to this email directly or view it on GitHub https://github.com/aaronc/fx-clj/issues/5#issuecomment-140756423.

aaronc avatar Sep 16 '15 15:09 aaronc

For me the line https://github.com/aaronc/fx-clj/blob/master/src/fx_clj/impl/bootstrap.clj#L4 prevents AOT, I've commented it out, called it in a fn during app startup and everything works.

QAston avatar Oct 16 '15 21:10 QAston

might (ns ^:no-doc ^:skip-aot fx-clj.impl.bootstrap) work ?

birdspider avatar Oct 20 '15 17:10 birdspider

I have hit this problem. The ^:skip-aot did not solve the compilation hang. Removing the line entirely made the compile succeed. But then adding it into the main application made the compile hang again in the main application. Eventually I got the compile working by moving (javafx.embed.swing.JFXPanel.) into the actual mainline code. But then there is a different problem. lein run works. And lein uberjar compiles. But running the jar file with java command line doesn't work giving: java.lang.IllegalStateException: Toolkit not initialized

retrogradeorbit avatar Aug 10 '16 04:08 retrogradeorbit

You need to call (javafx.embed.swing.JFXPanel.) before you use javafx. You can see a working example here: https://github.com/QAston/URDMI/blob/master/src/urdmi/gui_util.clj (see init-toolkit fn)

QAston avatar Aug 10 '16 10:08 QAston

I just remembered that some controls may have static initializers that cause this error. In that case you need to call the static initializer later (lookup the class dynamically instead of refering to it statically from clojure).

QAston avatar Aug 10 '16 10:08 QAston

I did call (javafx.embed.swing.JFXPanel.). Does your working example uberjar? To reiterate again:

  1. When (javafx.embed.swing.JFXPanel.) is defonced, lein uberjar hangs
  2. When (javafx.embed.swing.JFXPanel.) is put inside the mainline, lein uberjar 'works', but the compiled jar when run directly from java -jar doesn't work, raising a java.lang.IllegalStateException: Toolkit not initialized. (lein run DOES work with this method, just the packaged jar fails)

I have given up on this approach and am now building my JavaFX app by directly extending the JavaFX Application classes via gen-class, as you would build it in Java. When I do this it all works, including the uberjar running under java -jar.

retrogradeorbit avatar Aug 10 '16 11:08 retrogradeorbit

This is an example of a launcher class that works in AOT and is written in clojure https://github.com/QAston/URDMI/blob/master/src/urdmi/launcher.clj

QAston avatar Aug 10 '16 12:08 QAston