0

I have created an java application that i would like to convert to MacOS .app. I managed to run java packager against my jar file, which created .pkg file for me. After installation app is starting (preloader) but it end with .fxml file load problem due to '!' char that is added for some reason to path:

javafx.fxml.LoadException: 
file:/Applications/app.app/Contents/Java/app.jar!/programGUI.fxml

Jar file is working fine when is located on other location that /Applications/app.app/. I already tried to start it manually from Application/app.app/Contents/Java/ and Application/app.app/Contents/MacOS/, but result was the same (even with sudo). I tired to change permissions (chmod) plus system preferences (system preferences > privacy) but still no luck.

ClassLoader classLoader = this.getClass().getClassLoader();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/programGUI.fxml"));
Parent root = loader.load();

Worth to mention that in similar way I am loading background picture for preloader and it is working.

Image backgroundImage = new Image(classLoader.getResource("splashScreen.png").toString());

Any suggestion would be appreciated.

Edit: Adding Main Class as requested

public class Main extends Application {
    private BooleanProperty ready = new SimpleBooleanProperty(false);

    @Override
    public void start(Stage primaryStage) {
        try {
            myStart();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        ready.addListener(new ChangeListener<Boolean>() {
            public void changed(
                    ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                if (Boolean.TRUE.equals(t1)) {
                    Platform.runLater(new Runnable() {
                        public void run() {
                            try {
                                ClassLoader classLoader = this.getClass().getClassLoader();
                                FXMLLoader loader = new FXMLLoader();
                                loader.setClassLoader(getClass().getClassLoader());
                                loader.setLocation(getClass().getResource("/programGUI.fxml"));
                                Parent root = loader.load();
                                Scene scene = new Scene(root, 900, 600);
                                primaryStage.setScene(scene);
                                primaryStage.setTitle("myName");
                                primaryStage.setResizable(false);
                                primaryStage.getIcons().add(new Image(classLoader.getResource("icon.png").toString()));
                                primaryStage.show();
                            } catch (IOException ex) {
                                System.out.println(ex.getMessage());
                            }
                        }
                    });
                }
            }
        });
    }
    private void myStart() throws Exception {
        Task task = new Task<Void>() {
            @Override
            protected Void call() throws Exception {
            FileDownloader fd = new FileDownloader(new URL("www.example.com/myfile.txt"));
                while (fd.status == 0) { //0 = downloading, 2 = completed
                    try {
                        Thread.sleep(50);
                        if (fd.getProgress() > 0) {
                            notifyPreloader(new Preloader.ProgressNotification((fd.getProgress())));
                        }
                        if (fd.status == 100) {
                            ready.setValue(Boolean.TRUE);
                            notifyPreloader(new Preloader.StateChangeNotification(
                                    Preloader.StateChangeNotification.Type.BEFORE_START));
                        }
                    } catch (InterruptedException ex) {
                        System.out.println(ex.getMessage());
                    }
                }
                return null;
            }
        };
        Thread t = new Thread(task);
        new Thread(task).start();
    }

    public static void main(String[] args) {
        LauncherImpl.launchApplication(Main.class, myPreloader.class, args);
    }
}

Thanks in advance, Piotr

wolffiq
  • 1
  • 2
  • Hi, can you post the class main please? – vincenzopalazzo Jul 16 '19 at 15:15
  • @vincenzopalazzo added to 1st post – wolffiq Jul 16 '19 at 19:26
  • Thanks, I have to need more information, an example the structure of the project, if you used some construction system (ant maven or gradle) – vincenzopalazzo Jul 16 '19 at 21:48
  • @vincenzopalazzo I am not using any of it. Just straight forward javaFX project. – wolffiq Jul 17 '19 at 06:16
  • a question for you, because javapackager generated a pkg and not an .app? is your configuration? – vincenzopalazzo Jul 18 '19 at 12:17
  • 1
    @vincenzopalazzo I managed to fix the issue. It was caused by .fxml controler. For some reason i did not get any details why javafx.fxml.LoadException happen and i assumed that it was connected with the location. After I cleared all onAction properties and renamed all objects that I was calling from controller class problem was resolved. Nevertheless thanks for your effort vincenzopalazzo – wolffiq Jul 19 '19 at 15:06

0 Answers0