Reputation: 41
I am trying to run SpringBoot Application in the same codebase with Minecraft Forge Mod. I am on version 1.12.2 with ForgeGradle "2.3". Everything runs fine while running with Intellij. But when I put my fatJar inside the server's mods folder it throws the following:
[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
When I see "NoClassDefFoundError" I thought jar file hadn't got the commons-logging dependency. So i checked inside, everything were there. I crated the jar file with shadowJar plugin.
Some of the things I tried:
compile fileTree(dir: 'libs', include: '*.jar')
and carried the commons' jar file with mod jar. But server threw the same exception.Here is my 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'
}
}
Any help would much appreciated
Upvotes: 0
Views: 355
Reputation: 1
I have ran into the same issue recently. I did some debugging, and it turns out:
net.minecraft.launchwrapper.LaunchChassLoader
. This class loader will refuse to load some classes in some packages with some prefix (depends on classLoaderExceptions
)org.apache.commons.
inside classLoaderExceptions
.Therefore, any classes with package prefix org.apache.commons.xxxxxx
in a mod .jar, will not be loaded. Therefore, you cannot use any classes like so directly or indirectly (even if the class you're using is not apache-common-logging) in your mods.
Obviously, AbstractApplicationContext
references org.apache.commons.logging.LogFactory
(from spring-jcl), so you'll get a NoClassDefFoundError
.
The reason your mod runs fine with Intellij, is that runClient
task will pass paths of every dependencies as classpath to minecraft server, so the AppClassLoader
will find and load org.apache.commons.logging.LogFactory
successfully.
I don't know any solution yet.
ps: related to https://github.com/MinecraftForge/FML/issues/424
Upvotes: 0