gpt4 book ai didi

java - gradle 多项目出现 NoClassDefFoundError

转载 作者:太空宇宙 更新时间:2023-11-04 09:22:48 24 4
gpt4 key购买 nike

我已经在java中设置了一个gradle多项目。构建成功,但是当我尝试运行 JAR 时,抛出了 java.lang.NoClassDefFoundError。

这是我的项目结构:

.gradle/
authserver/
build/
src/main/java/fr/evywell/robserver/auth/
Main.java
build/
common/
build/
src/main/java/fr/evywell/robserver/common/
gradle/
build.gradle
settings.gradle

然后是我的配置:settings.gradle(在根目录中)

rootProject.name = "robserver"

include 'authserver'
include 'common'

build.gradle(在根目录中)

subprojects {
apply plugin: 'java'

repositories {
mavenCentral()
}
}

build.gradle(在公共(public)目录中)

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'io.netty', name: 'netty-all', version: '4.1.24.Final'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
compile group: 'org.javassist', name: 'javassist', version: '3.25.0-GA'
compile group: 'com.jsoniter', name: 'jsoniter', version: '0.9.23'
}

build.gradle(在 authserver 目录中)

apply plugin: 'application'

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'io.netty', name: 'netty-all', version: '4.1.24.Final'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
compile group: 'org.javassist', name: 'javassist', version: '3.25.0-GA'
compile group: 'com.jsoniter', name: 'jsoniter', version: '0.9.23'
compile project (':common')
}

mainClassName = 'fr.evywell.robserver.auth.Main'

jar {
manifest {
attributes 'Main-Class': 'fr.evywell.robserver.auth.Main'
}
}

错误消息:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: fr/evywell/robserver/common/network/Server
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: fr.evywell.robserver.common.network.Server
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

错误消息表明它无法在我的 common 包中找到类。我不知道为什么,因为我在我的 authserver gradle 配置中使用了 compile project (':common')

命令如下:java -jar authserver/build/libs/authserver.jar

感谢您的帮助,祝您有美好的一天!

最佳答案

对我来说,接下来的事情是:在 kotlin 中,我将 Spring Boot 插件应用于 root build.gradle 中的所有子项目 {}

我已经删除了这个从根 build.gradle 中 apply(plugin = "org.springframework.boot") 并将此行应用于每个子项目而不是 common 模块

关于java - gradle 多项目出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58113274/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com