I have a problem when compiling while using gen-class with static 
initializers. I use gen-class to extend a JavaFX 8 class, 
javafx.scene.control.Control. During compilation, a static initializer is 
run, raising an exception saying that the JavaFX toolkit has not been 
initialized. I'm going to share what I've read, since this issue seems to 
pop up from time to time, and see if there are better solutions than 
currently posted online. Here are my questions and comments:

   - Is there a way to run code during compilation that fires before the 
   static initializers? I could use this as a workaround to initialize the 
   toolkit.
   - Is there a way to stop the static initializers from being run? This 
   would solve the problem.
   - More broadly, is is necessary for gen-class to run the static 
   initializers during compilation? I recently read over CLJ-1315: 
   "Problem: When classes are imported in Clojure, the class is loaded using 
   Class.forName(), which causes its static initialisers to be executed. This 
   differs from Java where compilation does not cause classes to be loaded." I 
   wonder if a similar approach should be used with Clojure's gen-class.

Related discussions:

   - JIRA: CLJ-1315 <http://dev.clojure.org/jira/browse/CLJ-1315>
   - Compilation question - why initialize classes when loading for 
   compilation? 
   
<https://groups.google.com/forum/#!searchin/clojure/static$20initializers/clojure/Qd9KTKwqsOA/OigoOrcmoAkJ>
   - Stack Overflow: How can a static initializer be defined using gen-class 
   
<http://stackoverflow.com/questions/11783736/how-can-a-static-initializer-be-defined-using-gen-class>
   - Stack Overflow: Clojure can't import JavaFX classes with static 
   initializers 
   
<http://stackoverflow.com/questions/23365409/clojure-cant-import-javafx-classes-with-static-initializers>

Thanks,
David

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to