Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uberjar and compile #5

Open
ghost opened this issue Mar 28, 2015 · 11 comments
Open

uberjar and compile #5

ghost opened this issue Mar 28, 2015 · 11 comments

Comments

@ghost
Copy link

ghost commented Mar 28, 2015

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
  ...)
@KPCCoiL
Copy link

KPCCoiL commented Sep 16, 2015

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.

@aaronc
Copy link
Owner

aaronc commented Sep 16, 2015

Can anyone post a stack trace?
On Wed, Sep 16, 2015 at 3:56 AM KPCCoiL notifications@github.com 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
#5 (comment).

@KPCCoiL
Copy link

KPCCoiL commented Sep 16, 2015

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.

@aaronc
Copy link
Owner

aaronc commented Sep 16, 2015

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 notifications@github.com 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
#5 (comment).

@QAston
Copy link

QAston commented Oct 16, 2015

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.

@birdspider
Copy link

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

@retrogradeorbit
Copy link

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

@QAston
Copy link

QAston commented Aug 10, 2016

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
Copy link

QAston commented Aug 10, 2016

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).

@retrogradeorbit
Copy link

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.

@QAston
Copy link

QAston commented Aug 10, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants