You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven依赖已存在于Eclipse,Minecraft插件仍报NoClassDefFoundError

解决Minecraft Maven插件中JDA依赖的NoClassDefFoundError问题

我帮你分析下这个问题——你遇到的java.lang.NoClassDefFoundError: net/dv8tion/jda/core/hooks/ListenerAdapter本质是Minecraft服务器的类加载机制导致的:虽然Eclipse编译时能找到JDA的类,但你的插件Jar里并没有把JDA的依赖正确打包进去,服务器运行时自然找不到这些类。独立项目能正常运行是因为它的类加载环境和Minecraft插件完全不同,默认会包含依赖类。

结合你的pom.xml配置,问题出在这几个地方:

  • 同时使用了maven-assembly-plugin和maven-shade-plugin,两个插件功能重叠会导致打包异常
  • maven-shade-plugin版本太老(1.6是非常旧的版本),可能存在打包不完整的bug
  • 没有配置包重定向(Relocation),容易和服务器上其他使用JDA的插件产生类冲突

解决方案步骤

1. 清理冲突的打包插件

移除maven-assembly-plugin,因为maven-shade-plugin已经能完成将依赖打包进Jar的功能,两者共存会干扰打包结果。

2. 更新并配置maven-shade-plugin

将maven-shade-plugin升级到最新稳定版本,并添加包重定向配置,避免类冲突。修改后的build部分配置如下:

<build>
  <sourceDirectory>src</sourceDirectory>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>3.5.1</version> <!-- 升级到最新稳定版 -->
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <!-- 配置包重定向,把JDA的类重命名到你自己的包下,避免冲突 -->
            <relocations>
              <relocation>
                <pattern>net.dv8tion.jda</pattern>
                <shadedPattern>com.gmail.JyckoSianjaya.DonateCraft.jda</shadedPattern>
              </relocation>
            </relocations>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

3. 重新打包并使用正确的Jar文件

在项目根目录执行Maven命令:

mvn clean package

打包完成后,在target目录下找到带有-shaded后缀的Jar文件(比如DonateCraftV653-0.0.1-SNAPSHOT-shaded.jar),将这个Jar文件放到Minecraft服务器的plugins目录下运行。

额外说明

  • 包重定向(Relocation)是必须的:Minecraft服务器上可能有其他插件也使用JDA,不重定向的话会出现类版本冲突,导致插件无法加载
  • 确保JDA依赖的scope是compile:你当前的配置已经是compile,这是正确的,这样shade插件才会将其打包进去

内容的提问来源于stack exchange,提问作者Jicko Sianjaya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:48:23