当前位置: 首页 > 知识库问答 >
问题:

Minecraft Forge Gradle添加了外部依赖项,但没有将依赖项构建到jar中

韦繁
2023-03-14

这是我的毕业档案

buildscript {
    repositories {
        maven { url = 'https://files.minecraftforge.net/maven' }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true
        classpath files('libs/json-lib-2.4-jdk15.jar')
    }
}
tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}
apply plugin: 'net.minecraftforge.gradle'
group = 'siongsng.rpmtwupdatemod'
version = '1.0.0'
archivesBaseName = 'rpmtw_update_mod'
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8'
minecraft {
    mappings channel: 'snapshot', version: '20210309-1.16.5'
    runs {
        client {
            workingDirectory project.file('run')
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
            property 'forge.logging.console.level', 'debug'
            mods {
                rpmtwupdatemod {
                    source sourceSets.main
                }
            }
        }
        server {
            workingDirectory project.file('run')
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
            property 'forge.logging.console.level', 'debug'
            mods {
                rpmtwupdatemod {
                    source sourceSets.main
                }
            }
        }
        data {
            workingDirectory project.file('run')
            property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
            property 'forge.logging.console.level', 'debug'
            args '--mod', 'rpmtwupdatemod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
            mods {
                rpmtwupdatemod {
                    source sourceSets.main
                }
            }
        }
    }
}
sourceSets.main.resources { srcDir 'src/generated/resources' }
dependencies {
    implementation files('libs/json-lib-2.4-jdk15.jar')
    minecraft 'net.minecraftforge:forge:1.16.5-36.1.1'
}
jar {
    manifest {
        attributes([
                "Specification-Title"     : "rpmtwupdatemod",
                "Specification-Vendor"    : "SiongSng",
                "Specification-Version"   : "1",
                "Implementation-Title"    : project.name,
                "Implementation-Version"  : version,
                "Implementation-Vendor"   : "SiongSng",
                "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
        ])
    }
}
jar.finalizedBy('reobfJar')

然而,当我使用gradlebuild时,当输出jar在Minecraft中运行时会发生以下错误

java.lang.NoClassDefFoundError: net/sf/json/JSONObject
    at siongsng.rpmtwupdatemod.json.get(json.java:29) ~[rpmtw_update_mod:1.0.0]
    at siongsng.rpmtwupdatemod.json.ver(json.java:38) ~[rpmtw_update_mod:1.0.0]
    at siongsng.rpmtwupdatemod.RpmtwUpdateMod.<init>(RpmtwUpdateMod.java:27) ~[rpmtw_update_mod:1.0.0]
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64) ~[?:?]
    at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
    at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) ~[?:?]
    at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) ~[?:?]
    at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:350) ~[?:?]
    at java.lang.Class.newInstance(Class.java:645) ~[?:?]
    at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:81) ~[forge:36.1]
    at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:120) ~[forge:?]
    at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1800) [?:?]
    at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1792) [?:?]
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) [?:?]
    at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1016) [?:?]
    at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1665) [?:?]
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1598) [?:?]
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183) [?:?]
Caused by: java.lang.ClassNotFoundException: net.sf.json.JSONObject
    at java.lang.ClassLoader.findClass(ClassLoader.java:719) ~[?:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:589) ~[?:?]
    at cpw.mods.modlauncher.TransformingClassLoader.loadClass(TransformingClassLoader.java:106) ~[modlauncher-8.0.9.jar:?]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[?:?]
    ... 19 more

这是json中的代码。JAVA

package siongsng.rpmtwupdatemod;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import net.sf.json.JSONObject;

public class json {
    public static JSONObject get() {
        StringBuilder json = new StringBuilder();
        try {
            URL urlObject = new URL("https://api.github.com/repos/SiongSng/ResourcePack-Mod-zh_tw/releases/latest");
            URLConnection uc = urlObject.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
            String inputLine = null;
            while ( (inputLine = in.readLine()) != null) {
                json.append(inputLine);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return JSONObject.fromObject(json.toString());
    }

    public static Object loadJson() {
        JSONObject aaa = get();
        return aaa.getJSONArray("assets").getJSONObject(0).get("browser_download_url");
    }

    public static Object ver() {
        JSONObject aaa = get();
        return aaa.get("tag_name");
    }
}

我猜这是因为这个jar中没有依赖项(json-lib),但是我在构建配置文件中设置了它,我想问一下是什么原因导致了这个mod的完整代码(https://github.com/SiongSng/RPMTW-Update-Mod/tree/master/1.16-forge)

共有1个答案

徐栋
2023-03-14

尝试使用实现组:'net。旧金山。json lib',名称:'json lib',版本:'2.4'这是您的依赖项

https://mvnrepository.com/artifact/net.sf.json-lib/json-lib/2.4

 类似资料:
  • 在命令行中,我需要构建一个没有依赖项的可执行jar。当前的“gradle build”命令给了我一个带有依赖项的jar。 在StackOverflow上找不到这个。如果是重复的问题,指给我看。谢谢。

  • null 0.0.1-快照 _remote.repositories Maven-metadata-local org-utility-0.0.1-snapshot.jar org-utility-0.0.1-snapshot.pom org-utility-0.0.1-snapshot-jar-with-dependencies.jar 因此,我能够将jar“retrieve org-utili

  • 问题内容: 我有一个依赖 然后我执行。添加了所有本机文件和远程Maven库,但是没有此jar。 更新 当我尝试通过运行应用程序时。它返回一个错误,指出上述依赖项中没有任何类(NoClassDefFoundError:de.matthiasmann.twl.ForExample)。我想将这个jar中的类添加到myjar.jar中(与maven使用远程依赖项相同)。我如何配置Maven来做到这一点?

  • npm是否有安装依赖作为对等依赖的选项,如yarn选项,而不是手动添加它例如: 感谢@Broncha,更新问题的更多说明 问题是如何向项目添加对等依赖。那就是 将依赖项添加到package.json中的“dependencies”中, 如何安装将其添加到package.json?中的“对等依赖”的依赖项

  • 我正在使用JBOSS EAP 6.1和JDK 1.6。我已将所有依赖项注册为静态模块。我对JDK API有依赖性 在部署期间,我面临以下问题: java。lang.NoClassDefFoundError:javax/crypto/CipherInputStream java。lang.NoClassDefFoundError:org/omg/CORBA/portable/IDLEntity ja

  • 我在build.gradle文件中添加了下面的依赖项。Eclipse插件是在build.gradle中添加的。 一旦我运行gradle eclipse命令,所有的compile依赖项都会添加到类路径中,但是testcompile依赖项不会添加到类路径中。