这是我的模块信息:
open module org.client.main {
exports org.apj.client.app;
requires javafx.controls;
requires javafx.base;
requires javafx.fxml;
requires spring.context;
requires spring.web;
requires java.sql;
requires spring.beans;
requires spring.core;
}
这是我的父级 gradle 构建文件:
subprojects {
afterEvaluate {
repositories {
jcenter()
}
compileJava {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}
compileTestJava {
inputs.property("moduleName", moduleName)
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'junit',
'--add-reads', "$moduleName=junit",
'--patch-module', "$moduleName=" + files(sourceSets.test.java.srcDirs).asPath,
]
classpath = files()
}
}
test {
inputs.property("moduleName", moduleName)
doFirst {
jvmArgs = [
'--module-path', classpath.asPath,
'--add-modules', 'ALL-MODULE-PATH',
'--add-reads', "$moduleName=junit",
'--patch-module', "$moduleName=" + files(sourceSets.test.java.outputDir).asPath,
]
classpath = files()
}
}
}
}
这是我的客户端模块构建文件:
plugins {
id 'java'
}
group 'APJ'
version '1.0-SNAPSHOT'
sourceCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.4.RELEASE'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
ext.moduleName = 'org.client.main'
我正在尝试获取 FXMLLoader 的资源,但我根本无法让它工作。我已经挣扎了2个小时了,现在我真的很绝望。我已经尝试了文件名的所有可能的组合、每个可能的位置,但它仍然返回 null。
我也尝试过ClassLoader.getSystemClassLoader().getResource("/login.fxml")
getClass().getResource("/login.fxml")
但它也不起作用。
有人可以帮我解决这个问题吗?我将非常感激。
最佳答案
我注意到 Java 11 有 2 个选项可以让 getResource 工作:
- 使用插件
'org.openjfx.javafxplugin'版本'0.0.7'
或 在上面 Slaw 提供的链接中使用“--patch-module”:Where do resource files go in a Gradle project that builds a Java 9 module?
run { doFirst { jvmArgs = [ '--module-path', classpath.asPath, '--patch-module', "$moduleName=" + files(sourceSets.main.output.resourcesDir).asPath, '--module', mainClassName ] } }
关于java - GetResource 方法在 java 11 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54317046/