简体   繁体   English

IntelliJ + Gradle + JavaFX 构建,但未运行

[英]IntelliJ + Gradle + JavaFX building, but not running

I'm trying to run Gradle project with JavaFX in IntelliJ IDEA Ultimate on Windows.我正在尝试在 Windows 上的 IntelliJ IDEA Ultimate 中使用 JavaFX 运行 Gradle 项目。 JavaFX was added in our latest Git push, before it was working. JavaFX 在它工作之前被添加到我们最新的 Git 推送中。

I can build project without problems.我可以毫无问题地构建项目。 I'm getting an errror while running main:运行 main 时出现错误:
在此处输入图片说明 I have:我有:

  • JDK 11.0.5 (the one from Oracle site, not openJDK), I'm using Java 11, all configured in IntelliJ JDK 11.0.5(来自 Oracle 站点,不是 openJDK),我使用的是 Java 11,全部在 IntelliJ 中配置
  • JDK installation directory (specifically /bin directory in it) added to my PATH JDK安装目录(特别是其中的/bin目录)添加到我的PATH
  • JAVA_HOME environment variable added with JDK installation directory添加JDK安装目录的JAVA_HOME环境变量

Project structure:项目结构:
在此处输入图片说明

build.gradle (it was not built by me, I don't understand exactly what is written there and why): build.gradle(它不是由我构建的,我不明白那里写的是什么以及为什么):

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:主.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.如果我理解正确,IntelliJ 会看到所有文件,代码中没有未解析的引用,所有导入都有效。

JavaFX jars are downloaded by Gradle: JavaFX jars 由 Gradle 下载:
在此处输入图片说明

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.它们被配置为“库”,而不是“全局库”,因为它们不应该是,如果我理解正确的话,应该使用 Gradle 构建它,下载所有内容并运行。

I've tried creating new project with Git Checkout, it didn't work.我试过用 Git Checkout 创建新项目,但没有用。 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).奇怪的是,虽然它对我的同事有用(他们有相同的设置:JDK 11、Java 11、Windows;有些甚至根本没有 JAVA_HOME 并且对他们有用)。

What I've tried:我试过的:

What else can I do?我还可以做些什么? I just want Gradle to download whatever I need and run this project.我只是想让 Gradle 下载我需要的任何东西并运行这个项目。 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).我们在大学里用 JavaFX 介绍了类似的项目,它确实适用于我当前的配置(唯一的区别是那个是使用 Maven 的)。

EDIT编辑
After running gradlew --info run I got:运行gradlew --info run我得到:

> 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.

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 .删除了compile group: 'org.openjfx', name: 'javafx', version: '11.0.2', ext: 'pom'作为gradle.build依赖gradle.build
  2. Changed mainClassName in gradle.build to mainClassName = "app.TransportCompanyApp" .mainClassName中的gradle.build更改为mainClassName = "app.TransportCompanyApp"
  3. Changed Run option in IntelliJ to use gradle run .将 IntelliJ 中的 Run 选项更改为使用gradle run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM