iCo*_*der 3 java javafx intellij-idea gradle openjfx
上下文:尝试使用OpenJdK11和OpenJFx11创建一个简单的JavaFx应用程序
问题:尝试执行时出现以下错误
Error: JavaFX runtime components are missing, and are required to run this application
Run Code Online (Sandbox Code Playgroud)
我提到了Link1和Link2。我还提到了“ JavaFx11入门”- 链接 正如我在尝试指定运行配置时在入门中所建议的那样,我收到一条消息,如下所示
run' in 'build' cannot be applied to '(groovy.lang.Closure)' less... (Ctrl+F1)
Run Code Online (Sandbox Code Playgroud)
希望面临的问题是明确的,并等待我出问题的地方。(使用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();
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
摇篮
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'
]
}
}
Run Code Online (Sandbox Code Playgroud)
小智 9
我从JavaFX的官方存储库中找到了一个解决方案:https : //github.com/javafxports/openjdk-jfx/issues/236
虽然有一些简单的解决方法。例如,您可以有一个不扩展javafx.application.Application的主类,然后该主类可以在您的实际主类上调用main(String [])方法(这样,Java启动器不需要javafx库作为命名模块提供)。
我用Intellij IDEA创建了一个Java工件,它可以正常工作(不使用gradle)。
| 归档时间: |
|
| 查看次数: |
3537 次 |
| 最近记录: |