0

Hi I've been researching stackoverflow for similar problems to mine. It's 2am night time but still searching. I found one JavaFX app doesn't launch. How can I find out why?

but he had a similar problem to me, but not the exact problem. He had a problem with naming the jar file. I think my problem falls in choosing the correct class name, I'm new to Java and MacOS just trying to understand the environment.

I have a success when building the jpackage converting .jar to .dmg but when I click on the app installed from dmg it doesn't open, and I left it the exact code as it is when creating a new project for a JavaFX app from Intellij. But it works when I run it on Intellij.

To reproduce the problem

  1. create a new javafx project from intellij

HelloApplication.java this is the code in the HelloApplication.java file

package com.example.demo;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

public class HelloApplication extends Application {
    @Override
    public void start(Stage stage) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
        Scene scene = new Scene(fxmlLoader.load(), 320, 240);
        stage.setTitle("Hello!");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch();
    }
}

2) build the jar file from build

3) run jpackage with this command

jpackage --input /Users/basaam/IdeaProjects/demo/ \
  --name c6app \
  --main-jar "/Users/basaam/IdeaProjects/demo/out/artifacts/demo_jar/" \
  --main-class com.example.demo \
  --type dmg \
  --icon "/Users/basaam/IdeaProjects/demo/out/artifacts/demo_jar/iconsx.icns" \
  --app-version "1.2.3" \
  --vendor "code tinkering" \
  --copyright "Copyright 2020 whoever" \
  --mac-package-name "App Name in Menu" \
  --module-path "/Users/basaam/Downloads/javafx-sdk-18.0.2/lib" \
  --add-modules javafx.controls,javafx.graphics,java.xml,jdk.xml.dom,javafx.fxml \
  --verbose \

I get this message

[17:36:13.097] Result DMG installer for c6: /Users/basaam/IdeaProjects/demo/out/artifacts/demo_jar/c6-1.2.3.dmg.
[17:36:13.098] Succeeded in building Mac DMG Package package


MacOS monterey version 12.5.1
Adam
  • 186
  • 1
  • 4
  • 20
  • 3
    See if you can run the installed app from the terminal, and report any error message you see. – James_D Sep 19 '22 at 01:21
  • 1
    It would also help to add the missing pieces to the question. Include how you created the jar file, or at least the contents of it, and include everything needed for the application. – James_D Sep 19 '22 at 14:08
  • 2
    All that said, the `--main-jar` and `--main-class` options both look wrong. `--main-jar` should be a jar file (it looks like you have a directory) and `--main-class` should be a fully qualified class name, not a package. – James_D Sep 19 '22 at 14:11
  • thanks james_D your really helped by asking me to open the app in terminal, it showed an error ``` Error: Could not find or load main class com.example.demo.App Caused by: java.lang.ClassNotFoundException: com.example.demo.App ``` – Basaam Qasem Sep 19 '22 at 16:00
  • so what I done now I changed the jpackage code to the" demo.jar" file main class to "HelloApplication" --main-jar "/Users/basaam/IdeaProjects/demo/out/artifacts/demo_jar/demo.jar" \ --main-class HelloApplication \ I got the same error in terminal Error: Could not find or load main class HelloApplication Caused by: java.lang.ClassNotFoundException: HelloApplication So I guess i'm using the wrong class name, now I'm looking for how to get the correct class name. Thanks – Basaam Qasem Sep 19 '22 at 16:28
  • 1
    You need the fully qualified class name. – James_D Sep 19 '22 at 16:42

0 Answers0