openjfx / javafx-maven-plugin

Maven plugin to run JavaFX 11+ applications
Apache License 2.0
372 stars 59 forks source link

Different problems on first use of plugin with javafx:compile and javafx:jlink #105

Open treimers opened 4 years ago

treimers commented 4 years ago

Hello,

I tried to follow the instructions from the main page in order to compile, run and link a JavaFX project with this Maven plugin.

I started with my own application and ran into problems. So I switched to HelloFX but the problems still remain.

First of all let's talk about my environment

The documentation states

Create a new Maven project, use an existing one like HelloFX, or use an archetype. The project can be modular or non-modular.

When I try to compile the HelloFX app with

mvn javafx:compile

I am getting an error

[ERROR] Could not find goal 'compile' in plugin org.openjfx:javafx-maven-plugin:0.0.4 among available goals jlink, run -> [Help 1]

So I tried to use

mvn compile

instead. This worked and I could start the app by

mvn javafx:run

But jlink did not work

mvn javafx:jlink ... [ERROR] Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.4:jlink (default-cli) on project hellofx: Error: jlink requires a module descriptor -> [Help 1]

What might I am doing wrong? Any help appreciated, thanks in advance.

betanzos commented 4 years ago

When I try to compile the HelloFX app with

mvn javafx:compile

I am getting an error

[ERROR] Could not find goal 'compile' in plugin org.openjfx:javafx-maven-plugin:0.0.4 among available goals jlink, run -> [Help 1]

Yes, this is a mistake in documentation. The goal javafx:compile was removed from current version (0.0.4). mvn compile could be use instead.

So I tried to use

mvn compile

instead. This worked and I could start the app by

mvn javafx:run

In fact, we don't need to run mvn compile before javafx:run, but we do when running javafx:jlink. Next version will fix this (see merged PR #69)

But jlink did not work

mvn javafx:jlink ... [ERROR] Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.4:jlink (default-cli) on project hellofx: Error: jlink requires a module descriptor -> [Help 1]

What might I am doing wrong?

In order to run a non-modular application you need to create a launcher class which no extend from Application (more info can be found in the JavaFX official documentation in section Non-modular application).

public class Launcher {
    public static void main(String[] args) {
        HelloApp.runApp(args);
    }
}
public class HelloApp extends Application {

    @Override
    public void start(Stage stage) {
        // here the code
    }

    public static void runApp(String[] args) {
        launch(args);
    }
}
abhinayagarwal commented 4 years ago

Documentation on compile has been fixed with #83