Minecraft Forge NoClassDefFoundError:org/apache/commons/logging/LogFactory

167 views Asked by At

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:

  • Tried to update to the ForgeGradle 3.+ but that didn't help.
  • Tried to put the library next to the jar file in server folder that didn't help as well.
  • Tried to copy all the code base related to commons-logging to mine with the same package name, it still ran with Intellij but failed to boot up when run inside the server.
  • Tried to force load the class from the jar file with custom class loader, but failed to do so.
  • Tried to use Log4j2 with Spring by adding "log4j2.xml" under the resources folder, as it seems like Forge uses Log4j2. But Spring still goes for commons-logging package.
  • Explicitly removed the commons-logging package, well that throw ClassNotFound, I don't know what did i expect.
  • Tried to load by putting this line inside the dependencies tag, 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

0

There are 0 answers