0

I'm a beginner person on Java and i have a little problem about making .jar files with Intellij IDEA. I'm trying to make a simple library management system for my daily use.

The first image is my project on IDE. When i click Run button on IDE, it's working without a problem.

The second image is my same project on IDE. I only changed my packages. I moved FXML files on mainJavaFiles package and deleted xmlFiles package. When i click Run button on IDE, it's working without a problem.

first image : https://i.stack.imgur.com/ZGvJZ.png

second image : https://i.stack.imgur.com/mZzMB.png

The problem is starting when i try to run .jar file. I can make .jar files with first and second pictures project structure, there is no problem. My .jar file is running without a problem with second pictures project structure. But my .jar file isn't running with first pictures project structure.

When i seperate my java and fxml files by using different packages, my jar file isn't running. What should i change to run my jar file with first pictures project structure. How can i solve this problem?

@Override
public void start(Stage primaryStage) throws Exception{
    Parent root = FXMLLoader.load(getClass().getResource("anaEkran.fxml"));
    primaryStage.getIcons().add(new Image(getClass().getResourceAsStream("book-open-icon.png")));
    primaryStage.setTitle("Kitaplık Yönetim Sistemi");
    primaryStage.setScene(new Scene(root));
    primaryStage.show();
}

2 Answers2

0

I suggest you read the following post to clarify how loading resources works. Preferred way of loading resources in Java

It looks like you are not using an independent build system like maven or gradle to produce your jar files. So, most likely you have not told intellij to include the files in the jar. I suggest unzipping the jar file and making sure all the expected files are there. If they are not then it seems likely that you have an intellij project config issue.

In the future I highly recommend using something like maven as it has a mostly formal directory structure that can help keep things structured.

Deadron
  • 5,135
  • 1
  • 16
  • 27
0

Try use a gradle. You can find many tutorials in internet about it. For example: https://www.mkyong.com/gradle/gradle-create-a-jar-file-with-dependencies/

Or if you looking for building independent JavaFx aplication example look at: https://github.com/klolo/fx/

You will need propably another structure of your project.

lolcio
  • 346
  • 5
  • 12