代码之家  ›  专栏  ›  技术社区  ›  Doctor One

Minecraft Forge不加载公共日志

  •  0
  • Doctor One  · 技术社区  · 3 年前

    我正在尝试使用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文件。

    我尝试过的一些事情:

    • 尝试更新到ForgeGradle 3.+,但没有帮助。
    • 尝试将库放在服务器文件夹中的jar文件旁边,但也没有帮助。
    • 尝试用相同的包名称复制所有与commons日志记录相关的代码库以挖掘,它仍然使用Intellij运行,但在服务器内部运行时未能启动。
    • 尝试使用自定义类加载器从jar文件强制加载类,但未能成功。
    • 尝试将Log4j2与Spring一起使用,方法是在resources文件夹下添加“Log4j2.xml”,因为看起来Forge使用的是Log4j2。但Spring仍然支持commons日志记录包。
    • 明确删除了commons日志记录包,好吧,抛出ClassNotFound,我不知道我期待什么。
    • 试图通过将此行放在依赖项标记内进行加载, compile fileTree(dir: 'libs', include: '*.jar') 并携带了带有mod jar的commons的jar文件。但服务器抛出了相同的异常。

    这是我的建筑.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'
        }
    }
    

    任何帮助都将不胜感激

    0 回复  |  直到 3 年前