Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App doesn't run on MacOS #141

Closed
2 of 5 tasks
ccc469 opened this issue Jan 25, 2022 · 14 comments
Closed
2 of 5 tasks

App doesn't run on MacOS #141

ccc469 opened this issue Jan 25, 2022 · 14 comments
Labels
help wanted Extra attention is needed

Comments

@ccc469
Copy link

ccc469 commented Jan 25, 2022

I'm submitting a…

  • bug report
  • feature request
  • other

Short description of the issue/suggestion:

Steps to reproduce the issue/enhancement:

  1. [First Step]
  2. [Second Step]
  3. [Other Steps...]

What is the expected behavior?

What is the current behavior?

Do you have outputs, screenshots, demos or samples which demonstrate the problem or enhancement?

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • JavaPackager version: 17.0.1
  • OS version: MacOS 10.15.7 Catalina
  • JDK version:
    java version "17.0.1" 2021-10-19 LTS
    Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
    Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
  • Build tool:
    • Maven
    • Gradle

Other information (e.g. related issues, suggestions how to fix, links for us to have context)

Originally posted by @fvarrui in #140 (comment)

@ccc469
Copy link
Author

ccc469 commented Jan 25, 2022

files.zip
Hi, Relevant files are in zip, Please help me 😊

@fvarrui
Copy link
Owner

fvarrui commented Jan 25, 2022

Hi!
Have you tried to run your installed app from the command line?

/Applications/javafx-demo.app/Contents/Home/MacOS/universalJavaApplicationStub

@fvarrui fvarrui added the help wanted Extra attention is needed label Jan 25, 2022
@fvarrui fvarrui changed the title I'm submitting a… App doesn't run on MacOS Jan 25, 2022
@fvarrui
Copy link
Owner

fvarrui commented Jan 25, 2022

If when you run your app from command line, you see something like Error: JavaFX runtime components are missing, and are required to run this application, the problem is that you have to specify JavaFX modules to the JVM.

Solution 1: pass --module-path and --add-modules params to JVM

<vmArgs>
    <vmArg>--module-path libs</vmArg>
    <vmArg>--add-modules javafx.controls,javafx.fxml</vmArg>
</vmArgs>

Above params are passed to "java". ⚠️ I've not tested this.

Solution 2: (the easiest in my opinion) use another class as main class

  1. Create a new class (e.g. Main) which not extends Application with a main method.
  2. Call HelloApplication.main (HelloApplication extends Application) method from Main.main.
  3. Now run the app calling Main.main.
  4. That's all!
public class HelloApplication extends Application {
    [...]
    public static void main(String [] args) {
        launch(args);
    }
    [...]
}
public class Main {
    public static void main(String [] args) {
        HelloApplication.main(args);
    }
}

Now, your mainClass should be Main, not App.

<mainClass>com.example.javafxdemo.Main</mainClass>

<mainClass>com.example.javafxdemo.HelloApplication</mainClass>

This solves the problem.

@ccc469
Copy link
Author

ccc469 commented Jan 25, 2022

image
Hi, I try to run according to your suggestion and return the result,
Is this a packaging configuration problem in my project?
image

@fvarrui
Copy link
Owner

fvarrui commented Jan 25, 2022

I anticipated the situation 😅 ... please, try what I explained above.

@ccc469
Copy link
Author

ccc469 commented Jan 25, 2022

According to your suggestion, the application can be installed and opened normally. Why?

@fvarrui
Copy link
Owner

fvarrui commented Jan 25, 2022

Did it work?

According to your suggestion, the application can be installed and opened normally. Why?

If you mean the 2nd solution, it's a trick 😅 . I'm not sure, I discovered it by accident, but I guess it has to do with the ClassLoader.

@fvarrui
Copy link
Owner

fvarrui commented Jan 25, 2022

This question is asked a lot here, but it really has nothing to do with JavaPackager... Please, could you share your project to use as an example for future users? It would allow me to improve the documentation of the project for those who develop JavaFX apps.

@ccc469
Copy link
Author

ccc469 commented Jan 25, 2022

image
I solved my problem according to scheme 2,At least it works in my environment

@fvarrui
Copy link
Owner

fvarrui commented Jan 25, 2022

Happy to help! I'm sure it works in any environment 😄

@fvarrui fvarrui closed this as completed Jan 25, 2022
@ccc469
Copy link
Author

ccc469 commented Jan 25, 2022

Hi, I still have some questions to ask you. Most of my customers use windows. How can I generate a complete one click installation package like DMG / PKG? The customer's computer may not install JRE environment. Please help me if there are examples

@fvarrui
Copy link
Owner

fvarrui commented Jan 25, 2022

According to your suggestion, the application can be installed and opened normally. Why?

I found an explanation ... follow this link.

@fvarrui
Copy link
Owner

fvarrui commented Jan 25, 2022

Hi, I still have some questions to ask you. Most of my customers use windows. How can I generate a complete one click installation package like DMG / PKG? The customer's computer may not install JRE environment. Please help me if there are examples

You have to generate an EXE installer (setup) or a MSI file, so your customers can easily install your app. You also can bundle a customized JRE (reduced/optimized) with your app, so your customers don't need to have Java installed on their systems. JavaPackager uses Inno Setup to generate EXE installers and WiX Toolset to generate MSI files, so that if you need these installation artifacts, you have to package your app from a Windows system.

If you don't need the EXE installer or MSI file, JavaPackager can generate a portable (compressed) application from MacOS for Windows. You just have to give JavaPackager the path to a Windows JDK. The portable version may also include a JRE, but users must unzip your application before they can use it.

@ccc469
Copy link
Author

ccc469 commented Jan 26, 2022

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants