Context: Trying to create a simple JavaFx application using OpenJdK11 & OpenJFx11
Issue: I get an error as below when I try to execute
Error: JavaFX runtime components are missing, and are required to run this application
I referred to Link1 & Link2 . I also referred to 'Getting started with JavaFx11' - Link
As suggested in the getting started when I try specifying the run configuration I get a message as shown
run' in 'build' cannot be applied to '(groovy.lang.Closure)' less... (Ctrl+F1)
Hope the issue faced is clear & await inputs as to where I am going wrong. (using IntelliJ ide)
Code:
Main -
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'
]
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…