Java FX path for .fxml files doesn´t work when exporting to JAR

I have a JavaFX project which runs this way:

    FXMLLoader loader = new FXMLLoader(getClass().getResource("Login.fxml"));
    

My folder scheme is like this:

enter image description here

It works great in Eclipse but when I export it into a Runnable JAR and execute it from the console, it does:

enter image description here

I put in the jar folder my Login.fxml different ways:

But none of this is working. Where I am supposed to place my Login.fxml file?

I would appreciate some help here. Thank you.

Upvotes: 0

Views: 481

Answers (2)

Piotr Ławniczak
Piotr Ławniczak

Reputation: 21

I noticed that non-java files have landed within src directory inside the jar, so I simply added src/ before fxml file path. Not the best solution but it allows to generate working runnable jar file.

Upvotes: 0

I got it:

My Login.fxml class was inside the application package. So i created a application folder inside the folder in wich the jar file is:

enter image description here

And inside application folder I peasted the Login.fxml file.

I also created res and src for other resources.

Upvotes: 1

Related Questions