JavaFX application will not open when converted jar to dmg

Viewed 45

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
0 Answers
Related