1

I obfuscated my javafx code that contains .fxml files for view. After successful obfuscation when i run the jar file using command line, it shows the error in main method that the code is unable to load .fxml file.

Please help

Ibrar
  • 11
  • 2
  • `FXMLLoader` works with fully qualified class names (among others the controller class's, if specified using `fx:controller`) and field/method names. Probably obfuscating the code modified some of those... – fabian Apr 05 '19 at 11:07
  • So is there any solution you suggest ? that would work? – Ibrar Apr 05 '19 at 15:19

1 Answers1

0

This may not be what your looking for, but you could always use a FXML to java converter to create an abstract class.
Then you have the controller for the xml file extend the abstract class, you'll have to remove the initialize method (it's no longer necessary) and change the @FXML annotation for any methods that handle events to @Overrides.
Also you'll no longer need any of the fields with an @FXML annotation as all controls will be accessible through the abstract base class. If you use Netbeans there is a plugin to do this available through the plugin portal, or a stand alone jar file can be found here: https://www.tutorialon.com/p/fxmltojavaconverter.html

Then instead of loading fxml you just use the class constructor. For example if the root element in your FXML is a BorderPane, then you would use something like

BorderPane borderPane = new MyClass();
  • Whay you say is completely irrelevant. My question is something else. – Ibrar Apr 11 '19 at 13:08
  • Well my point was that because fxml requires fully qualified class names , and because these fully qualified names change when obfuscated, then if you used my example, you would no longer have a requirement on the fxml at run time as your application would use the abstract classes created from the fxml files instead. Thus allowing you to obfuscate your code. –  Apr 11 '19 at 21:24