2

The problem: Running a JavaFX application that is based on a Maven non-module project (project name = “howdyjfx”) from the Eclipse IDE generates the following compilation error:

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project howdyjfx: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java are missing or invalid.

Development environment and configuration:

  • OS: Windows 10
  • IDE: Eclipse 2019-03 (4.11.0)
  • Installed JDK: jdk-11.0.3, this is the default (and only) JDK installed in the workspace. The project build path is Java SE-11 (jdk-11.0.3). Because Eclipse requires a Java 1.8 JRE, jdk1.8.0_211 is also installed on my computer; Eclipse will not run without this.
  • Builder: All projects are non-modular and compiled using Maven. Eclipse handles this with its built-in m2e feature.
  • Pom: Here's an extract from the pom:
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.spindotta.jfx11.testbed</groupId>
    <artifactId>howdyjfx</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-controls -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13-ea+8</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.openjfx/javafx-fxml -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>13-ea+8</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.2</version>

                <configuration>
                    <!-- Is this necessary? The 'Run' configuration goals are "clean exec:java" -->
                    <executable>C:\Program Files\Java\jdk-11.0.3\bin\java</executable>

                    <!-- Workaround to short-circuit jdk1.8 which is needed to run Eclipse 
                        but is toxic for jdk11 and higher -->
                    <options>
                        <option>-Djava.library.path=C:\tmp</option>
                    </options>

                    <!-- Main class - is this correct? -->
                    <mainClass>com.spindotta.jfx11.testbed.howdyjfx.HowdyJFX</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

The application code is:

    public class HowdyJFX extends Application {

         @Override
         public void start(Stage primaryStage) throws Exception {
              final String javaVersion = System.getProperty("java.version");
              final String javafxVersion = System.getProperty("javafx.version");
              final Label l = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
              final Scene scene = new Scene(new StackPane(l), 640, 480);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

The above configuration and code is based on the 'Getting Started' guide and Sr. Jose Pereda's Github post, and also on the answer to a similar question that was asked last September. For whatever reason, however, I can't get this to work. This is all the more frustrating because I'm finishing an extensive library of JFX controls that compile without any problems (using both JDK 11 and JavaFX 11) and work fine in Scene Builder (apart from some Scene Builder issues that aren't relevant here).

Thanks in advance for any useful suggestions!

jfr
  • 397
  • 2
  • 17
  • It looks like you are running Eclipse’s default goal, which might uses the default Maven plugin. You need to edit the configuration and add `mvn clean javafx:run`, as explained in the guide you have linked. Note also that the samples repo is not mine. – José Pereda Jun 10 '19 at 15:33
  • @JoséPereda Sorry for the confusion and thanks for your patience, I’m having problems with the editor; here’s the full comment (in three parts b/c of size limit). If the Run configurations -> Main tab -> Goals specifies either (i) `clean exec:java` or (ii) `clean exec:java javafx:run`, this generates the missing/invalid parameters for the 'mainClass' described in the error message in my question. ... – jfr Jun 11 '19 at 16:34
  • @JoséPereda If 'Goals' are changed to (i) `clean javafx:run` or (ii) `clean javafx:run exec:java` then a different error message results: `Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.2:run (default-cli) on project howdyjfx: Error: Command execution failed. Process exited with an error: 1 (Exit value: 1)`. The Run configurations -> JRE tab -> ‘VM arguments’ is empty. Should there be something here? Also, are the `` settings for the `javafx-maven-plugin` in the `pom` correct? (There are only two parts, this is the second). – jfr Jun 11 '19 at 16:36
  • 2
    You don't need both `exec:java` _and_ `javafx:run`. You only need _one_ plugin to run your project. `javafx:run` is what you need. If you have _other_ issues, then you have to find what are those issues and try to fix them. Edit your question with the new configuration and issues. Though comments is impossible to solve them. – José Pereda Jun 11 '19 at 16:37
  • 1
    @JoséPereda Thanks for your help, I answered the question myself. For what it's worth - and this is no reflection on you or OpenFX - the process for launching apps now compared to pre-JavaFX 11 is a nightmare and certainly not a step forward. Under the 'old' way, you need only configure your main class properly, then click the 'Run' (or 'Debug') option and you're good to go. For developers who are thinking about moving to JavaFX or expanding in that area, this is something that whoever makes the big decisions needs to keep in mind. Thanks again for you help! – jfr Jun 11 '19 at 21:36

1 Answers1

4

The configuration in the pom file is correct, but the specification for the main class in the <configuration> section of the javafx-maven-plugin is wrong. In the both the ‘Getting started’ guide and the material on the Github repo, the name for the mainClass is ‘ org.openjfx.hellofx.App, which is a combination of the <groupId> plus <artifactId> plus the simple class name. Because the <groupId> and <artifactId> for my project are com.spindotta.jfx11.testbed and howdyjfx, respectively, I combined them with the simple class name HowdyJFX. This was incorrect because the project has the standard Maven configuration source/main/java plus a top-level folder howdyjfx. Specifying howdyjfx/HowdyJFX as the mainClass in the plugin fixed the problem.

For what it’s worth, the items specified in the <configuration> for the javafx-maven-plugin are essential; omitting any will generate an ERROR. It should be possible to specify these values in the Run configurations -> JRE tab -> VM arguments, although I find it easier to handle this in the pom using a template.

Thanks to Jose Pereda for clarifying an issue with the Goals that must be specified in the Run configurations for the launch.

Now there is another problem. I need to be able to debug JavaFX applications that are launched by the method suggested in the Getting Started guide and the Github repo. I set an Eclipse breakpoint in the main class HowdyJFX at the first line where a variable is assigned, so that the application would stop at that point, which did not happen. Instead the application ran as if the breakpoint wasn’t there. This is a different issue than the one at hand and is raised elsewhere.

jfr
  • 397
  • 2
  • 17
  • I don't agree with this: `org.openjfx.hellofx.App, which is a combination of the plus `. That is your interpretation. Instead, it is simply the fully qualified name of the application [App class](https://github.com/openjfx/samples/blob/master/IDE/Eclipse/Non-Modular/Maven/hellofx/src/main/java/org/openjfx/hellofx/App.java), so that is the same argument for `` that is usually applied to Maven projects. It happens to be the combination of group and artifact, because that is how you usually create your package names. – José Pereda Jun 11 '19 at 21:59
  • The default configuration for the JavaFX Maven plugin is empty but the mainClass. That means all the possible options are set by default. These values can be changed of course, when needed. For instance, the `executable`, if there are issues with your IDE, as explained in the tutorial https://openjfx.io/openjfx-docs/#IDE-Eclipse, Maven sections. If you still feel that is an error, please file an [issue](https://github.com/openjfx/javafx-maven-plugin/issues) detailing which doesn't work if you leave it empty. – José Pereda Jun 11 '19 at 22:03
  • 1
    @JoséPereda Re your "I don't agree with this ... that is your interpretation", indeed that was my understanding, which I acknowledged and explained as an error, which was due to the fact/coincidence that the fully qualified class name and (ii) the combination of the `groupId`/`artificatId`/class name were identical. This possibility is noted and will be kept in mind in the future. And as for "how you usually create your package names", I follow a different practice ... and for very good reasons that have proven themselves useful and valid. Thank you again for your help. – jfr Jun 11 '19 at 22:33