【发布时间】:2018-12-06 20:17:07
【问题描述】:
我在使用 gradle 运行我的简单 javafx 应用程序时遇到问题。
我有空白的标准 sample.fxml 文件:
<GridPane fx:controller="de.hhn.se.pmt.flowertours.controllers.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>
在我的 src 文件夹中,Intellij 和 gradle 不要抱怨。 gradle build 成功执行,但 gradle run 总是在 xmlns:fx="http://javafx.com/fxml" 行失败。
我的 build.gradle 看起来像这样:
plugins {
id 'java'
id 'checkstyle'
id 'jacoco'
id 'com.github.spotbugs' version '1.6.5'
}
apply plugin: 'application'
group 'de.hhn.se.pmt'
version '1.0-SNAPSHOT'
mainClassName = 'de.hhn.se.pmt.flowertours.Main'
allprojects{
compileJava {
options.encoding = 'UTF-8'
sourceCompatibility '1.8'
targetCompatibility '1.8'
}
repositories {
google()
jcenter()
mavenLocal()
mavenCentral()
}
}
repositories {
flatDir{
dirs "libs"
}
}
dependencies {
compile project (':gen')
compile name: 'orm'
compile name: 'jfxrt'
compile group: 'com.jfoenix', name: 'jfoenix', version: '1.2.0'
//logging with slf4j
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.24'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
//use JUnit 5
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
testCompile 'org.assertj:assertj-core:3.11.1'
}
添加的库 omr 和子项目 gen 尚未使用,不应执行(因此它们不应该是问题)。 jfxrt 库试图修复它,但没有必要。
我的 Main.java 看起来像这样:
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("/fxml/sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
/**
* "main" method that starts the program.
*
* @param args start parameter
*/
public static void main(String[] args) {
launch(args);
}
}
看起来在运行时缺少 javafx 库,但包含 jfxrt 和 runtime name: 'jfxrt' 并不能解决问题。
我做错了什么?这是我必须在 Intellij 中解决的问题吗?
【问题讨论】:
-
Is it a problem I have to fix in Intellij?如果使用 Gradle 从命令行失败,则 build.gradle 配置中存在问题。请发布您得到的实际错误和您使用的 JDK。
标签: java gradle intellij-idea javafx