IntelliJ + Gradle + JavaFX构建,但未运行 [英] IntelliJ + Gradle + JavaFX building, but not running

查看:127
本文介绍了IntelliJ + Gradle + JavaFX构建,但未运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Windows上的IntelliJ IDEA Ultimate中使用JavaFX运行Gradle项目.在工作之前,JavaFX已添加到我们最新的Git推送中.

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.

我可以毫无问题地构建项目.运行main时出现错误:
我有:

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

  • JDK 11.0.5(一个来自Oracle站点的文件,不是openJDK),我使用的是Java 11,均在IntelliJ中配置
  • 将JDK安装目录(特别是其中的/bin目录)添加到了我的PATH
  • 在JDK安装目录中添加了JAVA_HOME环境变量

项目结构:

Project structure:

build.gradle(它不是我构建的,我不知道那里到底写了什么以及为什么):

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:

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);
    }
}

如果我理解正确,那么IntelliJ会看到所有文件,代码中没有未解决的引用,所有导入都可以工作.

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

JavaFX jar由Gradle下载:

JavaFX jars are downloaded by Gradle:

由于我不应该将它们配置为库",而不是全局库",如果我理解正确的话,应该使用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.

我尝试使用Git Checkout创建新项目,但没有成功.奇怪的是,尽管它对我的同事们有用(他们具有相同的设置:JDK 11,Java 11,Windows;有些甚至根本没有JAVA_HOME,但对他们有用).

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

我尝试过的事情:

  • JavaFX getting started
  • Error: JavaFX runtime components are missing, and are required to run this application with JDK 11
  • Error: JavaFX runtime components are missing - JavaFX 11 and OpenJDK 11 and Eclipse IDE
  • https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000909940-Openjfx-11
  • https://openjfx-dev.openjdk.java.narkive.com/aFiw9uqi/error-javafx-runtime-components-are-missing-and-are-required-to-run-this-application
  • using JDK 13 and Java 13
  • changing project to modular
  • using JavaFX as Global Library and importing it to modules

我还能做什么?我只希望Gradle下载所需的文件并运行该项目.我们在大学里用类似的项目介绍了JavaFX,并做到了这一点,并且它确实适用于我当前的配置(唯一的区别是那个是与Maven一起使用的.)

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

编辑
运行gradlew --info run之后,我得到了:

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.

推荐答案

问题已解决.我做了什么:

The problem was solved. What I did:

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

这篇关于IntelliJ + Gradle + JavaFX构建,但未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆