0

Is there a way to compile FXML files into binary?

My problem is that some FXML files are loading too long, and users are able to modify them within the JAR files.

Anil
  • 655
  • 1
  • 11
  • 25
Marcel
  • 1,606
  • 16
  • 29
  • There is no binary fxml. All the FXML files are converted to Java Code during runtime. – ItachiUchiha Sep 23 '15 at 09:38
  • @ItachiUchiha This is not correct. FXML files will be packed inside the jar, but not converted to java code. – aw-think Sep 23 '15 at 10:30
  • If you want to avoid **easy** modifying of your FXML files, you probably need to drop the FXML approach and make it with pure Java Code. – aw-think Sep 23 '15 at 10:43
  • @NwDx I was not talking about how they are packaged. I was talking about how `FXMLoader` takes the FXML and creates a SceneGraph out of it using reflection. May be I should be more descriptive when I comment ;) – ItachiUchiha Sep 23 '15 at 10:53
  • @ItachiUchiha And I should read more carefully :-) – aw-think Sep 23 '15 at 11:01
  • @Marcel To be a little descriptive, FXML files are not compiled, these are resources which are just copied to the class path and loaded via FXMLoader during run time. FXML takes time to load because they are loaded via reflection. You can either not use FXML or [look for a way](http://tomsondev.bestsolution.at/2013/08/29/convert-fxml-to-java-as-part-of-the-build/) to convert it to java as a part of the build. – ItachiUchiha Sep 23 '15 at 11:06
  • I would guess that just reading the FXML file from the jar file is more of a bottleneck than the fact they use reflection (though I might be wrong). However, I've never seen the time to load an FXML as a prohibitive factor in any way. You load FXML files at startup or in response to user action, which are not performance critical moments anyway. Can you explain more about what you're doing that causes them to take "too long" to load? Maybe there is another solution. – James_D Sep 23 '15 at 11:48
  • I know that they are not compiled. Anyway i have an project on a Raspberry pi where i want to speed up start Time (just an example). I think the best way is to switch to Java Code there. An other example is where using FXML in a ListView as the CellFactory (Very bad) but currently we have no Time to change that. So i thought maybe there is a way to quickly compile them to speed that ListView up. – Marcel Sep 23 '15 at 14:52
  • This question is almost a duplicate of: [Is there a way to compile / load fxml files faster and only one time, and not at every restart of an application?](http://stackoverflow.com/questions/24077524/is-there-a-way-to-compile-load-fxml-files-faster-and-only-one-time-and-not-at) – jewelsea Sep 23 '15 at 23:26

1 Answers1

1

Currently, there is no support for binary FXML files out-of-the-box.

There is an issue filed for this however: https://bugs.openjdk.java.net/browse/JDK-8090360

Also e(fx)clipse was working on such a tool, but I don't know the status:

http://tomsondev.bestsolution.at/2013/08/29/convert-fxml-to-java-as-part-of-the-build/

https://bugs.eclipse.org/bugs/show_bug.cgi?id=408419

Puce
  • 37,247
  • 13
  • 80
  • 152