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