我一直在寻找将 FXML 和图像包含在build.gradle
以便将它们构建到罐子中。我有看here https://stackoverflow.com/questions/21128652/location-is-required-in-javafx-with-gradle并尝试了但它仍然不起作用。
抛出这个错误:java.lang.NullPointerException: inputStream is null.
这里是build.gradle
(Github https://github.com/Voidustries/Poly/blob/Gradle-Migration-For-CI/build.gradle):
group 'com.voidustries'
version '1.0-SNAPSHOT'
sourceSets {
main {
resources {
srcDirs = ["src/main/java/com/voidustries/poly"]
includes = ["gui/layoutForm.fxml"]
}
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.1.0'
}
}
apply plugin: 'java'
apply plugin: 'org.junit.platform.gradle.plugin'
repositories {
mavenCentral()
}
dependencies {
testCompile('org.junit.jupiter:junit-jupiter-api:5.1.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.1.0')
}
task wrapper(type: Wrapper) {
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '4.3.1'
}
test {
testLogging {
events "passed", "skipped", "failed"
}
}
这是 GUI.java (Github https://github.com/Voidustries/Poly/blob/Gradle-Migration-For-CI/src/main/java/com/voidustries/poly/gui/GUI.java):
FXMLLoader loader = new FXMLLoader();
FileInputStream fis = new FileInputStream(settings);
ResourceBundle resourceBundle = new PropertyResourceBundle(fis);
loader.setResources(resourceBundle);
Parent root = loader.load(getClass().getResourceAsStream("layoutForm.fxml"));
Platform.setImplicitExit(false);
堆栈跟踪说loader.load(getClass().getResourceAsStream("layoutForm.fxml"));
导致错误
这是源树:
com
└───voidustries
└───poly
│ CustomFormatter.java
│ Main.java
│ PolyThreads.java
│ SysTray.java
│
├───gui
│ Controller.java
│ GUI.java
│ Icon.png
│ layoutForm.fxml
│
└───img
Icon.png
你可以看到layoutForm.fxml
and Icon.png
都在树上
这是输出树:
com
└───voidustries
└───poly
│ CustomFormatter.class
│ Main.class
│ PolyThreads.class
│ SysTray.class
│
└───gui
Controller.class
GUI.class
在外面的树中,它们都缺席,我已经摆弄了几个小时试图解决这个问题。任何帮助将不胜感激。
另外如果您需要更多here https://github.com/Voidustries/Poly/tree/Gradle-Migration-For-CI是 Github 存储库