我正在尝试在与 Minecraft Forge Mod 相同的代码库中运行 SpringBoot 应用程序。我使用的是版本 1.12.2,ForgeGradle“2.3”。使用 Intellij 运行时一切都运行良好。但是当我将 fatJar 放入服务器的 mods 文件夹中时,它会抛出以下内容:
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:178)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at net.mahmutkocas.mkutils.server.web.WebApplication.lambda$start$0(WebApplication.java:46)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1052]: at java.lang.Thread.run(Thread.java:750)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:106)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
[21:56:23] [SpringWeb/INFO] [STDERR]: [java.lang.ThreadGroup:uncaughtException:1061]: ... 3 more
当我看到“NoClassDefFoundError”时,我认为 jar 文件没有获得公共日志依赖项。于是我检查了一下里面,一切都在那里。我用 ShadowJar 插件创建了 jar 文件。
我尝试过的一些事情:
compile fileTree(dir: 'libs', include: '*.jar')
并使用mod jar携带commons的jar文件。但服务器抛出了同样的异常。这是我的build.gradle:
buildscript {
repositories {
jcenter()
maven { url = "https://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
plugins {
id 'java'
id "com.github.johnrengelman.shadow" version "1.2.3"
}
apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
version = '0.0.1'
group = 'net.mahmutkocas'
archivesBaseName = 'mkutils'
configurations.all {
exclude group: "org.springframework.boot", module:"spring-boot-starter-logging" // Conflicts with forge.
// exclude group: 'org.springframework', module: 'spring-jcl' // For removing the commons-logging
// exclude group: 'commons-logging', module: 'commons-logging' // For removing the commons-logging
}
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}
minecraft {
version = "1.12.2-14.23.5.2838"
runDir = "run"
mappings = "snapshot_20171003"
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '3.1.2'
compile 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.14'
compile 'org.springframework.boot:spring-boot-starter-web:2.7.14'
compile group: 'io.github.openfeign', name: 'feign-jackson', version: '9.3.1'
compileOnly 'org.projectlombok:lombok:1.18.28'
compile 'com.h2database:h2:2.1.214'
annotationProcessor 'org.projectlombok:lombok:1.18.28'
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else except the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
任何帮助将不胜感激