I have a problem running a Java program using JavaFX and Gradle, in the IntelliJ IDE. I've looked at many solutions to, what seems to be, the same problem, however none of these have worked.
This question: IntelliJ + Gradle + JavaFX building, but not running is very similar to the problems I'm experiencing, along with the fixes I've tried. However the solution did not work for me.
Currently I'm trying to get a very simple application running:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class GUI extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
var pane = new BorderPane();
var input = new TextField();
primaryStage.setScene(new Scene(pane));
primaryStage.show();
}
}
This application does run, when using the commandline and 'gradlew run', however it doesn't run when using the IntelliJ IDEA IDE.
What's weird is that if I remove the TextField 'input', the program runs no problem. This leads me to believe the problem having to do with the module java.controls. However this is imported in my build.gradle:
plugins {
id 'java'
id 'application'
id 'jacoco'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
repositories {
jcenter()
}
dependencies {
// Use JUnit Jupiter Engine for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.1'
// Allow for JUnit 4 legacy
testCompileOnly 'junit:junit:4.12'
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.5.1'
}
application {
mainClassName = 'bfst20.addressparser.GUI'
}
test {
useJUnitPlatform()
}
jar {
manifest {
attributes 'Main-Class': application.mainClassName
}
}
These 2 errors appear when trying to run the program with the TextField:
When looking at the projects libraries, you get this overview:
Which clearly shows the libraries being present.
When running 'gradlew --info run' I get the following output:
> Task :run
Caching disabled for task ':run' because:
Build cache is disabled
Task ':run' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Starting process 'command 'C:\Program Files\Java\jdk-11.0.4\bin\java.exe''. Working directory: C:\Users\ASUS\FST\handin1 Command: C:\Program Files\Java\jdk-11.0.4\bin\java.exe --add-modules javafx.controls,javafx.fxml --module-path C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-fxml\12.0.1\5397068b7fb8f8db6631242d78e14f7d6db07d51\javafx-fxml-12.0.1-win.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-controls\12.0.1\838555460c025b8df0fbc0fa03bf3f3767698f89\javafx-controls-12.0.1-win.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-graphics\12.0.1\18a01ffdd4edb82e7da3bc99937c6a608d1eaaa6\javafx-graphics-12.0.1-win.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-base\12.0.1\6f5947b255bb26e072862b3bb0c32d54d8effe84\javafx-base-12.0.1-win.jar -Dfile.encoding=windows-1252 -Duser.country=DK -Duser.language=da -Duser.variant -cp C:\Users\sande\OneDrive\Dokumenter\ITU\2. Semester\FST\handin1\build\classes\java\main;C:\Users\sande\OneDrive\Dokumenter\ITU\2. Semester\FST\handin1\build\resources\main;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-fxml\12.0.1\5397068b7fb8f8db6631242d78e14f7d6db07d51\javafx-fxml-12.0.1-win.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-controls\12.0.1\838555460c025b8df0fbc0fa03bf3f3767698f89\javafx-controls-12.0.1-win.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-controls\12.0.1\a6502999bdb947885c8d121a47d745d52a06577a\javafx-controls-12.0.1.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-graphics\12.0.1\18a01ffdd4edb82e7da3bc99937c6a608d1eaaa6\javafx-graphics-12.0.1-win.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-graphics\12.0.1\19ec56a15d7dd9c49112912547425b718485d7db\javafx-graphics-12.0.1.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-base\12.0.1\6f5947b255bb26e072862b3bb0c32d54d8effe84\javafx-base-12.0.1-win.jar;C:\Users\Ejer\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-base\12.0.1\6abae81d00e0c6f4fde02e2666f9c0b989ff47e4\javafx-base-12.0.1.jar bfst20.addressparser.GUI
Successfully started process 'command 'C:\Program Files\Java\jdk-11.0.4\bin\java.exe''
:run (Thread[Daemon worker,5,main]) completed. Took 28.566 secs.