Gradle OpenJFx11:错误 - 缺少 JavaFx 运行时组件
Gradle OpenJFx11 : Error - JavaFx runtime components are missing
上下文:尝试使用 OpenJdK11 和 OpenJFx11
创建一个简单的 JavaFx 应用程序
问题: 当我尝试执行时出现如下错误
Error: JavaFX runtime components are missing, and are required to run this application
我提到了 & Link2 . I also referred to 'Getting started with JavaFx11' - Link
正如开始时所建议的,当我尝试指定 运行 配置时,我收到一条消息,如图所示
run' in 'build' cannot be applied to '(groovy.lang.Closure)' less... (Ctrl+F1)
希望所面临的问题是明确的,并等待关于我哪里出错的输入。 (使用 IntelliJ ide)
代码:
主要-
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/Sample.fxml"));
StackPane stackPane = new StackPane(root);
Scene scene = new Scene(stackPane);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.show();
}
}
FXML-
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="Controller"
prefHeight="400.0" prefWidth="600.0">
</AnchorPane>
Gradle-
plugins {
id 'java'
}
group 'testJavaFx'
version '1.0-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
compile 'org.openjfx:javafx-base:11:win'
compile 'org.openjfx:javafx-controls:11:win'
compile 'org.openjfx:javafx-fxml:11:win'
compile 'org.openjfx:javafx-graphics:11:win'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
}
run {
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
}
我从 JavaFX 的官方存储库中找到了解决方案:https://github.com/javafxports/openjdk-jfx/issues/236
There are some easy workarounds though. For example, you can have a main class that is not extending javafx.application.Application, and that main class can then call the main(String[]) method on your real main class (that way, the Java launcher doesn't require the javafx libraries to be available as named modules).
我用 Intellij IDEA 创建了一个 java 工件并且它可以工作(不使用 gradle)。
上下文:尝试使用 OpenJdK11 和 OpenJFx11
创建一个简单的 JavaFx 应用程序问题: 当我尝试执行时出现如下错误
Error: JavaFX runtime components are missing, and are required to run this application
我提到了
run' in 'build' cannot be applied to '(groovy.lang.Closure)' less... (Ctrl+F1)
希望所面临的问题是明确的,并等待关于我哪里出错的输入。 (使用 IntelliJ ide)
代码:
主要-
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/Sample.fxml"));
StackPane stackPane = new StackPane(root);
Scene scene = new Scene(stackPane);
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.show();
}
}
FXML-
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="Controller"
prefHeight="400.0" prefWidth="600.0">
</AnchorPane>
Gradle-
plugins {
id 'java'
}
group 'testJavaFx'
version '1.0-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
dependencies {
compile 'org.openjfx:javafx-base:11:win'
compile 'org.openjfx:javafx-controls:11:win'
compile 'org.openjfx:javafx-fxml:11:win'
compile 'org.openjfx:javafx-graphics:11:win'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
}
run {
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'javafx.controls'
]
}
}
我从 JavaFX 的官方存储库中找到了解决方案:https://github.com/javafxports/openjdk-jfx/issues/236
There are some easy workarounds though. For example, you can have a main class that is not extending javafx.application.Application, and that main class can then call the main(String[]) method on your real main class (that way, the Java launcher doesn't require the javafx libraries to be available as named modules).
我用 Intellij IDEA 创建了一个 java 工件并且它可以工作(不使用 gradle)。