ClassDefNoFound,即使我依赖的jar在我的jar中

问题描述 投票:0回答:1

我正在编写LabyMod插件来为我的世界的客户创建购物机器人。

至少在我的Eclipse开发环境中,我已经成功地做到了。现在,我想发布它,并为此做准备,LabyMod提供了一种可能性,可以使用gradle将与插件相关的所有内容包装到插件罐中,然后可以将其简单地拖动到“插件”文件夹中。 >

但是,当我这样做时,该插件未出现在插件概述中,并且我发现加载该插件时出现错误(找不到Class def)。我使用okhttp3将一些Web请求发送到我的验证服务器,因此我只是将其添加到eclipse中作为依赖jar,但在gradle构建jar时不包括在内。因此,我对此并不感到惊讶,并寻找一种将我的依赖项直接添加到jar中的可能性。

我在预定义build.gradle的注释中发现,可以将所有文件简单地放入预定义的“ libs”文件夹中,这似乎很好。问题出在这里:尽管jar确实是jar的一部分,但classdefnotfound仍然会发生。这就是我的意思。

JD-GUI说我的罐子:Contents of the jar

因此,罐子肯定在那里,并且jd-gui也可以在代码中找到它们,因为您可以单击导入,并转到okhttp3定义导入类的位置。

然而,这是尝试加载插件时遇到的错误:

catching
java.lang.NoClassDefFoundError: okhttp3/OkHttpClient$Builder
    at borg.locutus.grieferbot.utils.NetworkUtilities.sendGet(NetworkUtilities.java:70)
    at borg.locutus.grieferbot.utils.NetworkUtilities.getPermissionLevelOfPlayer(NetworkUtilities.java:51)
    at borg.locutus.grieferbot.GrieferBOTAddon.initPermissionLevel(GrieferBOTAddon.java:50)
    at borg.locutus.grieferbot.GrieferBOTAddon.onEnable(GrieferBOTAddon.java:43)
    at net.labymod.addon.AddonLoader.enableAddon(AddonLoader.java:349)
    at net.labymod.addon.AddonLoader.enableAddons(AddonLoader.java:309)
    at net.labymod.main.LabyMod.init(LabyMod.java:256)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:211)
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:189)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74)
    at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47)
    at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322)
    at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304)
    at com.google.common.eventbus.EventBus.post(EventBus.java:275)
    at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:118)
    at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:737)
    at net.minecraftforge.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:310)
    at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:495)
    at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:329)
    at net.minecraft.client.main.Main.main(SourceFile:124)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
Caused by: java.lang.ClassNotFoundException: okhttp3.OkHttpClient$Builder
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 44 more
Caused by: java.lang.NullPointerException
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)
    ... 46 more

如何使我的jar找到缺少的依赖项?

我正在编写LabyMod插件,以为Minecraft客户创建一个购物机器人。我已经成功地做到了,至少在我的Eclipse开发环境中。现在我想发布它,并做到这一点,LabyMod ...

java gradle dependencies minecraft minecraft-forge
1个回答
0
投票

您不能只将依赖项jar放入主jar。您需要将依赖项着色到其中。

© www.soinside.com 2019 - 2024. All rights reserved.