1

I'm trying to run Gradle project with JavaFX in IntelliJ IDEA Ultimate on Windows. JavaFX was added in our latest Git push, before it was working.

I can build project without problems. I'm getting an errror while running main:
enter image description here I have:

  • JDK 11.0.5 (the one from Oracle site, not openJDK), I'm using Java 11, all configured in IntelliJ
  • JDK installation directory (specifically /bin directory in it) added to my PATH
  • JAVA_HOME environment variable added with JDK installation directory

Project structure:
enter image description here

build.gradle (it was not built by me, I don't understand exactly what is written there and why):

plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

group 'transportCompany'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'org.mongodb:mongodb-driver-sync:3.11.2'
    compile group: 'org.openjfx', name: 'javafx', version: '11.0.2', ext: 'pom'
}

javafx {
    version = "11.0.2"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

Main.java:

public class TransportCompanyApp extends Application {

    private Stage primaryStage;
    private MainAppPresenter presenter;

    @Override
    public void start(Stage primaryStage) {

        this.primaryStage = primaryStage;
        this.primaryStage.setTitle("My first JavaFX app");
        presenter = new MainAppPresenter(primaryStage);
        this.presenter.initRootLayout();
        //this.primaryStage.show();

    }

    public static void main(String[] args) {
        launch(args);
    }
}

If I understand correctly, IntelliJ sees all files, there are no unresolved references in code, all imports work.

JavaFX jars are downloaded by Gradle:
enter image description here

They are configured as "Libraries", not "Global libraries", since they shouldn't be, with Gradle it should just be built, download everything and run, if I understand correctly.

I've tried creating new project with Git Checkout, it didn't work. Curiously though it worked for my colleagues (they have the same setup: JDK 11, Java 11, Windows; some even don't have JAVA_HOME at all and it works for them).

What I've tried:

What else can I do? I just want Gradle to download whatever I need and run this project. We've done that at university with JavaFX introduction with similar project and it did work on my current configuration (the only difference was that that one was with Maven).

EDIT
After running gradlew --info run I got:

> Task :run FAILED
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.5\bin\java.exe''. Working directory:
C:\Users\Lenovo\Desktop\TO Command: C:\Program Files\Java\jdk-11.0.5\bin\java.exe --add-modules
 javafx.controls,javafx.fxml --module-path C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\o
rg.openjfx\javafx-fxml\11.0.2\b3242e4c031558574de2a1da685bb5fcdbb8a530\javafx-fxml-11.0.2-win.j
ar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-controls\11.0.2\6c7637
07769c18adce406904c771c2ad1fcc370b\javafx-controls-11.0.2-win.jar;C:\Users\Lenovo\.gradle\cache
s\modules-2\files-2.1\org.openjfx\javafx-graphics\11.0.2\20459ea2cf714942bcbeb78a7f70ba3531dc1a
44\javafx-graphics-11.0.2-win.jar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjf
x\javafx-base\11.0.2\1852e57b8cf9a9b6488c33605bccd5d06ff210e1\javafx-base-11.0.2-win.jar -Dfile
.encoding=windows-1250 -Duser.country=PL -Duser.language=pl -Duser.variant -cp C:\Users\Lenovo\
Desktop\TO\build\classes\java\main;C:\Users\Lenovo\Desktop\TO\build\resources\main;C:\Users\Len
ovo\.gradle\caches\modules-2\files-2.1\org.mongodb\mongodb-driver-sync\3.11.2\a011ecee75c110e95
d33ece066f4bee149d5487a\mongodb-driver-sync-3.11.2.jar;C:\Users\Lenovo\.gradle\caches\modules-2
\files-2.1\org.openjfx\javafx\11.0.2\6e90384c9fb4ec7ed8186c0e916c419c87a24cbf\javafx-11.0.2.pom
;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-fxml\11.0.2\b3242e4c0315
58574de2a1da685bb5fcdbb8a530\javafx-fxml-11.0.2-win.jar;C:\Users\Lenovo\.gradle\caches\modules-
2\files-2.1\org.openjfx\javafx-controls\11.0.2\6c763707769c18adce406904c771c2ad1fcc370b\javafx-
controls-11.0.2-win.jar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-c
ontrols\11.0.2\4ab633cf1eea60f76e2ae9905aedac862da88b08\javafx-controls-11.0.2.jar;C:\Users\Len
ovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-graphics\11.0.2\20459ea2cf714942bcbeb
78a7f70ba3531dc1a44\javafx-graphics-11.0.2-win.jar;C:\Users\Lenovo\.gradle\caches\modules-2\fil
es-2.1\org.openjfx\javafx-graphics\11.0.2\e522eb4ea422eceeee207b1c266ba3db19b2343a\javafx-graph
ics-11.0.2.jar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.openjfx\javafx-base\11.0.
2\1852e57b8cf9a9b6488c33605bccd5d06ff210e1\javafx-base-11.0.2-win.jar;C:\Users\Lenovo\.gradle\c
aches\modules-2\files-2.1\org.openjfx\javafx-base\11.0.2\7fb2e4a8528ec9e434a9ac9ee98b39af79e6dc
b8\javafx-base-11.0.2.jar;C:\Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.mongodb\mongod
b-driver-core\3.11.2\798e2d948326c5bfd9924e524bab22ee39c8f4f\mongodb-driver-core-3.11.2.jar;C:\
Users\Lenovo\.gradle\caches\modules-2\files-2.1\org.mongodb\bson\3.11.2\96b17202f1250736ba83021
ff56550e83e8fd8c5\bson-3.11.2.jar TransportCompanyApp
Successfully started process 'command 'C:\Program Files\Java\jdk-11.0.5\bin\java.exe''
Error: Could not find or load main class TransportCompanyApp
Caused by: java.lang.ClassNotFoundException: TransportCompanyApp
:run (Thread[Daemon worker,5,main]) completed. Took 0.367 secs.

FAILURE: Build failed with an exception.

qalis
  • 1,314
  • 1
  • 16
  • 44
  • How do you run the app? As Java Application from IntelliJ or using Gradle tasks (either Gradle Window from IntelliJ or from terminal)? – José Pereda Dec 14 '19 at 13:11
  • @JoséPereda from IntelliJ, with Gradle, I think. At least when I use "run" option, the Gradle starts and tries to run my main. – qalis Dec 14 '19 at 13:52
  • Make sure you do use the gradle tasks. The best test you can try is running from a terminal, with `gradlew --info run`. If you still have the same error, post it (as text, not as image). – José Pereda Dec 14 '19 at 14:08
  • @JoséPereda I added it as an edit. – qalis Dec 14 '19 at 14:13
  • You need to set `mainClassName = "app.TransportCompanyApp"` in your build file. At least you didn't post it. (Make sure you set the correct name) – José Pereda Dec 14 '19 at 14:16
  • @JoséPereda I did it, didn't change anything – qalis Dec 14 '19 at 16:06
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/204262/discussion-between-qalis-and-jose-pereda). – qalis Dec 14 '19 at 18:44

1 Answers1

1

The problem was solved. What I did:

  1. Removed compile group: 'org.openjfx', name: 'javafx', version: '11.0.2', ext: 'pom' as dependency from gradle.build.
  2. Changed mainClassName in gradle.build to mainClassName = "app.TransportCompanyApp".
  3. Changed Run option in IntelliJ to use gradle run.
qalis
  • 1,314
  • 1
  • 16
  • 44