1

I am getting an error message when attempting to run a simple javafx application. Using netbeans 11.0, openjdk 12, openjfx12. Can't extract module name from javafx-12.0.1.pom: Only outputDirectories and jars are accepted on the path

I had similar problems to Alex on this question, as I wanted to be able to debug: I can't debug an application using netbeans 11 with JavaFX 12

I previously to use the javafx-archetype-fxml as suggested by https://openjfx.io/openjfx-docs/

but had difficulty running.

I tried to follow the steps suggested by Jose. Using the pom (with the application name changed):-

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.kev</groupId>
    <artifactId>MavenFX</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>MavenFX</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <organization>
        <!-- Used as the 'Vendor' for JNLP generation -->
        <name>Your Organisation</name>
    </organization>

    <dependencies>
        <!-- JavaFx 12 dependancies -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx</artifactId>
            <version>12.0.1</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>12.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>12.0.1</version>
            <type>jar</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>12</source>
                    <target>12</target>

                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.2</version>
                <executions>
                    <execution>
                        <!-- Default configuration for running -->
                        <id>default-cli</id>
                        <configuration>
                            <mainClass>org.kev.mavenfx.MainApp</mainClass>
                        </configuration>
                    </execution>
                    <execution>
                        <!-- Configuration for debugging -->
                        <id>debug</id>
                        <configuration>
                            <options>
                                <option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:8000</option>
                            </options>
                            <mainClass>org.kev.mavenfx.MainApp</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

I then modified the nbactions.xml as suggested:-

<actions>
    <action>
        <actionName>run</actionName>
        <goals>
            <goal>clean</goal>
            <goal>javafx:run</goal>
        </goals>
    </action>
    <action>
        <actionName>jlink</actionName>
        <goals>
            <goal>clean</goal>
            <goal>javafx:jlink</goal>
        </goals>
    </action>
    <action>
        <actionName>debug</actionName>
        <goals>
            <goal>clean</goal>
            <goal>javafx:run@debug</goal>
        </goals>
    </action>
</actions>

The project will happily build with no errors.

However on trying to run the project I get the following error message:-

cd G:\OneDrive\Documents\NetBeansProjects\MavenFX; "JAVA_HOME=C:\\Program Files\\OpenJDK\\jdk-12.0.1" cmd /c "\"\"C:\\Program Files\\Netbeans 11\\java\\maven\\bin\\mvn.cmd\" -Dmaven.ext.class.path=\"C:\\Program Files\\Netbeans 11\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean javafx:run\""
Scanning for projects...

------------------------------------------------------------------------
Building MavenFX 1.0-SNAPSHOT
------------------------------------------------------------------------

--- maven-clean-plugin:2.5:clean (default-clean) @ MavenFX ---
Deleting G:\OneDrive\Documents\NetBeansProjects\MavenFX\target

--- javafx-maven-plugin:0.0.2:run (default-cli) @ MavenFX ---
Using 'UTF-8' encoding to copy filtered resources.
Copying 2 resources
Changes detected - recompiling the module!
Compiling 2 source files to G:\OneDrive\Documents\NetBeansProjects\MavenFX\target\classes
Can't extract module name from javafx-12.0.1.pom: Only outputDirectories and jars are accepted on the path
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --module-path
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
        at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
        at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
        at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:447)
        at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:409)
        at org.openjfx.JavaFXRunMojo.execute(JavaFXRunMojo.java:97)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
        at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
        at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
        at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:447)
        at org.openjfx.JavaFXBaseMojo.executeCommandLine(JavaFXBaseMojo.java:409)
        at org.openjfx.JavaFXRunMojo.execute(JavaFXRunMojo.java:97)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.827 s
Finished at: 2019-08-07T23:18:12+01:00
Final Memory: 19M/70M
------------------------------------------------------------------------
Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.2:run (default-cli) on project MavenFX: Error: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

I can't understand the line: Can't extract module name from javafx-12.0.1.pom: Only outputDirectories and jars are accepted on the path

Kev
  • 43
  • 1
  • 4
  • `Unrecognized option: --module-path` means you are running NetBeans with Java 1.8. One way to fix it is by editing `C:\path\to\NetBeans11\etc\netbeans.conf`, and add the JDK 12, like documented here https://openjfx.io/openjfx-docs/#IDE-NetBeans. Also it should be better to use NetBeans 11.1. – José Pereda Aug 08 '19 at 08:32
  • @José Pereda I'm trying new NB11.1, and this time I don't even have JDK1.8 as a platform, just JDK12. I can confirm that the netbeans.conf reads 'netbeans_jdkhome="C:\Program Files\OpenJDK\jdk-12.0.1"'. I made the example OpenJFX, HelloFXMLWithMaven, which builds. On Run action I get `--- javafx-maven-plugin:0.0.2:run (default-cli) @ HelloFXMLWithMaven --- Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Unrecognized option: --module-path`. So confused. – Kev Aug 08 '19 at 20:25
  • Make sure you don't have a different JDK in your Windows Path environment variable. Also you could try adding `C:\Program Files\OpenJDK\jdk-12.0.1\bin\java` to the plugin's configuration and try again? – José Pereda Aug 08 '19 at 20:39
  • @JoséPereda You are correct! the issue was I had forgotten to make the OpenJDK12 my default java in windows `%PATH%`. Your adding of the specific executable as above makes it run (though debug gives an error but that is a new question I think). If you make this an answer then of course I will mark it so, or else I can make an answer to explain the solution. – Kev Aug 08 '19 at 21:35

2 Answers2

1

As discussed in the comments:

If you get the error Unrecognized option: --module-path, it means you are running with Java 1.8.

If you are running your Maven project from an IDE, it also means that your IDE is using JDK 1.8 as well.

There are two options to fix this issue:

In case of NetBeans, with the IDE closed, you can edit C:\path\to\NetBeans11.1\etc\netbeans.conf, and add the JDK 12 path, like documented here:

netbeans_jdkhome="C:\path\to\jdk-12.0.2"

Save, close the file, and open NetBeans again, and run the project, it should work. Note this is a permanent solution.

If still doesn't work, make sure you don't have in your PATH variable an older JDK. It is frequent to have the JDK bin path added to the Path environment variable, and if that is the case, that will be still chosen by your IDE.

The other option is to use <executable> in your JavaFX Maven plugin, like:

<configuration>
    <executable>C:\path\to\jdk-12.0.2\bin\java</executable>
    ...
</configuration>

Now, regardless the JDK of your IDE, it will pick the one in that path. Obviously, this makes your pom less portable.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • Thank you Jose for deducing this. I had thought that setting java_home was enough, but jdk 12 also has to be included in the %path% as well. The above workaround is successful if you don't want to add jdk12 to your path. – Kev Aug 10 '19 at 09:02
0

Download NetBeans 11.1. Create a new project. Go to samples and openjfx. Select the simple archetype.

enter image description here

SedJ601
  • 12,173
  • 3
  • 41
  • 59
  • OK, so I have now downloaded NB 11.1 (thanks for the tip). I have created a new HelloFXMLWithMaven sample project. While it builds ok (note in this new NB11.1, the only platform is JDK12), when attempting to run it I get similar error message: `--- javafx-maven-plugin:0.0.2:run (default-cli) @ HelloFXMLWithMaven --- Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. Unrecognized option: --module-path'` – Kev Aug 08 '19 at 20:16
  • Thanks, yes, and I checked the netbeans.conf file has ` netbeans_jdkhome="C:\Program Files\OpenJDK\jdk-12.0.1"` - still this error message – Kev Aug 08 '19 at 20:36
  • Did you remove `#` to uncomment that line? – SedJ601 Aug 08 '19 at 20:40