【发布时间】:2021-09-03 03:16:26
【问题描述】:
上下文:尝试使用 OpenJdK11 和 OpenJFx11 创建一个简单的 JavaFx 应用程序
问题:尝试执行时出现如下错误
Error: JavaFX runtime components are missing, and are required to run this application
我提到了 Link1 和 Link2 。我还提到了“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'
]
}
}
【问题讨论】:
-
将
application插件添加到您的构建文件中,您还需要将javafx.fxml添加到—add-modules -
@JoséPereda 谢谢,但即使在将 {javafx.fxml} 添加到 {--add-modules} 后仍然出现同样的错误。我什至添加了基础和图形,但仍然是同样的错误。还有什么做错了吗?已编辑:添加了编译Java和运行的模块,仍然错误
-
你添加了应用插件吗?你能从终端
./gradlew run运行吗? -
我添加了应用程序插件,删除了构建中的运行无法应用于消息。但是执行时的错误仍然存在。如果我从 Intellij 的终端运行“gradlew run”,它会返回 gradlew 无法识别。如果我运行“gradle run”,它会说构建失败......任务执行失败:运行
-
gradlew仅在您使用 Gradle 包装器时才有效。另外,您是否为application插件定义了mainClassName?
标签: java gradle intellij-idea javafx openjfx