Java 13: Why are javaFX runtime components missing?

ぐ巨炮叔叔 提交于 2020-05-28 07:02:09

问题


Error Message: Error: JavaFX runtime components are missing, and are required to run this application

LOOK HERE: project structure photo

I have downloaded the javafx extentions for the project as well as the jar file and attached it, the program knows javafx is there since the code errors went away. However, it then said there were no docs and no it says there's no JavaFx runtime components. I have been hiting error after error trying to get javafx to just run a hello world program in eclipse.


回答1:


JavaFX was removed from Java 11.

It's no longer shipped with the JDK, you need to install it separately (it's now a distinct product called OpenJFX).




回答2:


JavaFX is no longer provided in the builds after Java 10; however commercial support for JavaFX in JDK 8 (LTS) will continue through at least 2022.

You can now use OpenJFX Project, which is the open source home of JavaFX development. It's sponsored by the Swing Group.




回答3:


It's support was removed in Java 11 and it's now a different project. Their documentation specifies how to get started with JavaFX. I am just copy pasting it here because it is very well defined:

  1. Create a Maven project:

    • Create a File -> New -> Project... -> Maven -> Maven project. The first time you will need to add the JavaFX archetypes: Select Add Archetypes... and type: org.openjfx for the group id, javafx-archetype-simple or javafx-archetype-fxml for the artifact id, and 0.0.1 for the version.
    • Type org.openjfx in the filter field and select the archetype, between javafx-archetype-fxml or javafx-archetype-simple, based on the use of FXML or not in your project.
    • Provide the groupId, like org.openjfx, the artifactId, like hellofx. You can edit the javafx-version property, and set it to 14, and the plugin version to 0.0.4.
    • When the project opens, select the JDK 14 for the project (File -> Properties -> Java Build Path -> Libraries).
  2. Verify the pom:

    • Edit the pom file, and and verify it has the javafx.controls and javafx.fxml dependencies and the javafx-maven-plugin with the mainClass set to hellofx/org.openjfx.hellofx.App.
  3. Verify the code:

    • Edit the module-info class. Rename the module to hellofx. Also, to prevent Eclipse from showing a warning when creating the Application class, add also the transitive modules to the file:
    • Verify the project contains the source code files, like the App main class:
  4. Run the project:

    • Click Run -> Run As -> Maven Build -> New launch configuration to create a new configuration. Name it hellofx, and add the required goals:

      clean javafx:run
      
    • Run the project Run -> Run As -> Maven Build -> hellofx -> Run.

      In case JAVA_HOME is not set to 14, running the project might fail. To avoid it, you can add the correct java command to the javafx-maven-plugin: <configuration><executable>/path/to/jdk-12/bin/java</executable></configuration>.

    • You can also open a terminal and run mvn clean javafx:run to run the project.
    • You might find this exception when running your project:

      Exception in thread "WindowsNativeRunloopThread" java.lang.NoSuchMethodError: <init>
      
    • This is happening running on Windows when Eclipse VM is set to Oracle JDK 1.8 using Maven or Gradle projects. A workaround for this is to edit eclipse.ini and change the -vm option to JDK 14. If that is not possible, another workaround is to add this VM argument to the javafx maven plugin:

      <configuration>
          <options>
              <option>-Djava.library.path=C:\tmp</option>
          </options>
          <mainClass>org.openjfx.hellofx.App</mainClass>
      </configuration>
      

Maven Repo



来源:https://stackoverflow.com/questions/60512068/java-13-why-are-javafx-runtime-components-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!