前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Error: JavaFX runtime components are missing, and are required to run this application with Gradle e

Error: JavaFX runtime components are missing, and are required to run this application with Gradle e

作者头像
Maynor
发布2021-12-07 13:03:56
1.3K0
发布2021-12-07 13:03:56
举报

1

I know this has been asked multiple times… but I can’t seem to find a solution.

我知道这个问题已经被问过很多次了… … 但是我似乎找不到解决办法。

Taken from this official guidelines example: https://openjfx.io/openjfx-docs/#gradle I went on and added in my build.gradle :

从这个官方指导方针的例子中可以看出: 我继续在我的建筑中添加了一些 https://openjfx.io/openjfx-docs/#gradle :

代码语言:javascript
复制
plugins {
 id ‘application’
 id ‘org.openjfx.javafxplugin’ version ‘0.0.8’
 }
javafx {
 version = ‘13’
 modules = [‘javafx.controls’]
 }
repositories {
 mavenCentral()
 }
mainClassName = “MyImage”
jar {
 manifest {
 attributes “Main-Class”: “$mainClassName”
 }
 from {
 configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
 }
 }
 which, by running gradle jar (or gradle build), should actually produce a jar which should include all the packages it builds it with, that is the entire javafx library.

通过运行 gradle jar (或 gradle build) ,实际上应该生成一个 jar,其中应该包含所有构建它的包,即整个 javafx 库。

However, when it builds successfully and then I proceed with running:

然而,当它构建成功后,我继续跑步:

java -jar build/libs/MyImage.jar

Java-jar build/libs/MyImage.jar

it still throws the error:

它仍然会抛出错误:

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

错误: JavaFX 运行时组件丢失,并且需要运行此应用程序

What am I missing?

我错过了什么?

(I use JDK 11)

(我使用 JDK 11)

3

In Java 11 the Java launcher detects that you’re extending javafx.application.Application and checks the modules are present. If you’re using plain old JARs then you’ll get the error

在 java11中,Java 启动器检测到您正在扩展 javafx.application。应用程序和检查模块是否存在。如果您使用的是普通的旧罐子,那么您将得到错误

Error: JavaFX runtime components are missing, and are required to run this application You have two choices. Setup your application to use the Java module system or the following workaround.

您有两个选择。将应用程序设置为使用 Java 模块系统或下列变通方法。

This workaround avoids the Java launcher check and will let the application run.

这个解决方案避免了 Java 启动器检查,并且允许应用程序运行。

public class MyImage { // <=== note - does not extend Application

代码语言:javascript
复制
public static class YourRealApplication extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        // whatever...
    }

}

public static void main(String[] args) {
    Application.launch(YourRealApplication.class);
}

}

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-10-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档