【发布时间】:2020-06-08 13:30:16
【问题描述】:
我有一个简单的 javaFx 项目。我决定创建一个模块信息来为我的项目需要 javaFX 库。在此之前我的程序运行良好,但现在
getClass().getClassLoader().getResource(resPath) 无法从我的资源中获取资源。每次运行我的应用程序时,我都会收到此消息:
没有为主类提供模块,假设是当前模块。最好以以下格式提供“mainClassName”:“$moduleName/a.b.Main”
这是我的 build.gradle:
plugins {
id 'java-library'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
version '1.0'
repositories {
jcenter()
}
plugins.withType(JavaPlugin).configureEach {
java {
modularity.inferModulePath = true
}
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
application {
mainModule = 'liug'
mainClass = 'render.Main'
}
javafx {
version = "13"
modules = ['javafx.controls', 'javafx.fxml']
}
还有模块信息:
module moduleInfo {
requires javafx.base;
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
opens controller to javafx.base, javafx.fxml, javafx.controls, javafx.graphics;
opens core to javafx.base, javafx.fxml, javafx.controls, javafx.graphics;
opens popups to javafx.base, javafx.fxml, javafx.controls, javafx.graphics;
opens render to javafx.base, javafx.fxml, javafx.controls, javafx.graphics;
opens stages to javafx.base, javafx.fxml, javafx.controls, javafx.graphics;
opens view to javafx.base, javafx.fxml, javafx.controls, javafx.graphics;
exports controller;
exports core;
exports popups;
exports render;
exports stages;
exports view;
exports core.buildings;
}
谁能说我做错了什么?
【问题讨论】:
-
javafx-gradle-plugin 也应用了gradle-modules-plugin,这可能与 6.4 中添加的新模块功能 Gradle 不兼容。如果他们尚未解决新版本的问题,您可能需要考虑向其中一个或两个提交问题。
-
我发现 javaFX 提供了通过 gradle (openjfx.io/openjfx-docs/#IDE-Intellij) 制作模块化 JavaFX 项目的机会。我按照说明在build.gradle中将
application{..}替换为mainClassName = "$moduleName/Main"。现在想法抛出:错误:Could not find or load main class Main in module render有什么想法吗? -
它是
module/main-class,这意味着我认为在你的情况下它应该是liug/render.Main。 -
当问题是:原因:java.lang.module.InvalidModuleDescriptorException: Package liug.render not found in module
-
我已经多次更改module-info名称,发现这个sn-p:
mainClassName = "$moduleName/Main"找到了一个与module-info名称同名的包。例如,如果我将 projectCityBuilder 设置为模块信息的名称,我的程序将抛出:Caused by: java.lang.module.InvalidModuleDescriptorException: Package projectCityBuilder not found in module