在 jar 文件中获取 NoClassDefFoundError

Getting NoClassDefFoundError in jar file

提问人:Timas_bro 提问时间:8/9/2023 最后编辑:Timas_bro 更新时间:8/20/2023 访问量:104

问:

我刚刚添加了新的依赖项:

<dependency>
    <groupId>com.github.hamza-cskn.obliviate-invs</groupId>
    <artifactId>core</artifactId>
    <version>4.1.13</version>
</dependency>

现在我收到 NoClassDef 错误。该库的创建者说这不是他的错。

下面是完整的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.timuzkas</groupId>
    <artifactId>megabox-clans</artifactId>
    <version>0.4</version>
    <packaging>jar</packaging>

    <name>megabox-clans</name>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>org.timuzkas.megaboxclans.Megabox_clans</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

    <repositories>
        <repository>
            <id>papermc-repo</id>
            <url>https://repo.papermc.io/repository/maven-public/</url>
        </repository>
        <repository>
            <id>sonatype</id>
            <url>https://oss.sonatype.org/content/groups/public/</url>
        </repository>
        <repository>
            <id>placeholderapi</id>
            <url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
        </repository>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
        <repository>
            <id>minebench-repo</id>
            <url>https://repo.minebench.de/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.destroystokyo.paper</groupId>
            <artifactId>paper-api</artifactId>
            <version>1.16.5-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.github.MilkBowl</groupId>
            <artifactId>VaultAPI</artifactId>
            <version>1.7</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.6.0</version>
            <type>maven-plugin</type>
        </dependency>
        <dependency>
            <groupId>com.github.hamza-cskn.obliviate-invs</groupId>
            <artifactId>core</artifactId>
            <version>4.1.13</version>
        </dependency>

        <dependency>
            <groupId>me.clip</groupId>
            <artifactId>placeholderapi</artifactId>
            <version>2.11.3</version>
            <scope>provided</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    </dependencies>
</project>

错误:

[12:55:07 WARN]: Unexpected exception while parsing console command "mtitle menu"
org.bukkit.command.CommandException: Unhandled exception executing command 'mtitle' in plugin megabox-clans v0.4
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[patched_1.16.5.jar:git-Purpur-1171]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:172) ~[patched_1.16.5.jar:git-Purpur-1171]
        at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchCommand(CraftServer.java:826) ~[patched_1.16.5.jar:git-Purpur-1171]
        at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchServerCommand(CraftServer.java:788) ~[patched_1.16.5.jar:git-Purpur-1171]
        at net.minecraft.server.v1_16_R3.DedicatedServer.handleCommandQueue(DedicatedServer.java:483) ~[patched_1.16.5.jar:git-Purpur-1171]
        at net.minecraft.server.v1_16_R3.DedicatedServer.b(DedicatedServer.java:450) ~[patched_1.16.5.jar:git-Purpur-1171]
        at net.minecraft.server.v1_16_R3.MinecraftServer.a(MinecraftServer.java:1416) ~[patched_1.16.5.jar:git-Purpur-1171]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1142) ~[patched_1.16.5.jar:git-Purpur-1171]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:293) ~[patched_1.16.5.jar:git-Purpur-1171]
        at java.lang.Thread.run(Thread.java:831) [?:?]
Caused by: java.lang.NoClassDefFoundError: mc/obliviate/inventory/Gui
        at org.timuzkas.megaboxclans.mtitle.onCommand(mtitle.java:241) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[patched_1.16.5.jar:git-Purpur-1171]
        ... 9 more

命令处理程序(未满):

} else if (args[0].equalsIgnoreCase("menu")) {
                new mtitleGui(Bukkit.getOfflinePlayer(sender.getName()).getPlayer(), plugin);
            }

GUI 类:

package org.timuzkas.megaboxclans;

import mc.obliviate.inventory.Gui;
import mc.obliviate.inventory.Icon;
import mc.obliviate.*;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.Configuration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.ItemStack;

import java.util.List;

public class mtitleGui extends Gui {

    Megabox_clans plugin;

    public String convertColors(String input) {
        // Convert "&" color codes
        String converted = ChatColor.translateAlternateColorCodes('&', input);

        // Convert hex color codes
        converted = converted.replaceAll("#([A-Fa-f0-9]{6})", ChatColor.COLOR_CHAR + "x$1");

        return converted;
    }

    public mtitleGui(Player player, Megabox_clans plugin) {
        super(player, "mtitle", "Титулы", 6);
        this.plugin = plugin;
    }

    @Override
    public void onOpen(InventoryOpenEvent event) {
        for (int i = 0; i == 9; i++) {
            if (i == 5) {
                addItem(new Icon(Material.EMERALD).setName("Меню титулов").setLore("Специально для megabox"));
            } else {
                addItem(Material.GRAY_STAINED_GLASS_PANE);
            }
        }
        Icon info = new Icon(Material.PAPER).setName("Информация").appendLore("Титулы можно получать разными способами").appendLore("Получить от админов, купить").appendLore("Получить в розыгрыше").setAmount(1).hideFlags();
        addItem(10, info);
        for (int i = 0; i < 9; i++) {
            addItem(19 + i, Material.GRAY_STAINED_GLASS_PANE);
        }
        //--
        Configuration cf = plugin.getConfig();
        List titleslist = plugin.getConfig().getList("players." + player.getName() + ".titleslist");
        for (int i = 0; i < titleslist.size(); i++) {
            int finalI = i;
            addItem(28 + i, new Icon(Material.NAME_TAG).setName(convertColors(cf.getString("titles." + titleslist.get(i) + ".prefix"))).setLore("Клик чтобы установить").onClick(e -> {
                e.getWhoClicked().closeInventory();
                Player pl = Bukkit.getOfflinePlayer(e.getWhoClicked().getName()).getPlayer();
                pl.sendMessage(convertColors("&a&lТитул установлен!"));
                cf.set("players." + pl.getName() + ".set_title", titleslist.get(finalI));
            }));
        }
    }
}

我也尝试过 One-Jar,但我无法让它工作。

修复此错误。我需要它从 .jar 文件运行。我正在使用 PaperSpigot API、IntellijIDEA、Maven 和一些依赖项

EDI。添加了Megabox_clans或主类:

package org.timuzkas.megaboxclans;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.timuzkas.megaboxclans.commandtabcompleters.clanCompletion;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public final class Megabox_clans extends JavaPlugin {


    String prefix  = "[MEGABOX | CLANS]";

    private static Economy econ = null;

    public void log(String msg) {
        getLogger().info(msg);
    }

    private boolean setupEconomy() {
        if (getServer().getPluginManager().getPlugin("Vault") == null) {
            return false;
        }
        RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            return false;
        }
        econ = rsp.getProvider();
        return econ != null;
    }
    @Override
    public void onEnable() {
        PluginManager pluginManager = Bukkit.getPluginManager();
        pluginManager.registerEvents(new PlayerLeaveListener(this), this);
        saveDefaultConfig();
        log ("Hooking PAPI...");
        if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
            new PAPIExpansion(this).register();
        }
        log("Creating commands...");
        this.getCommand("clan").setExecutor(new Commands(this));
        this.getCommand("tech").setExecutor(new CommandTech(this));
        this.getCommand("mtitle").setExecutor(new mtitle(this));
        this.getCommand("mhec").setExecutor(new CommandProverka(this));
        //- Completers
        this.getCommand("clan").setTabCompleter(new clanCompletion(this));
        //-Economy
        if (!setupEconomy() ) {
            getLogger().severe(String.format("[%s] - Плагин Vault не найден, или нету экономики! Я выключаюсь, бип, боп!!", getDescription().getName()));
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
//--



        File myfile = new File("plugins/Megabox_clans/playerdata.yml");
        if (!myfile.exists()) {
            try {
                myfile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        //-----

        File myfile2 = new File("plugins/Megabox_clans/clans.yml");
        if (!myfile2.exists()) {
            try {
                myfile2.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        //-----



    }

    public static Economy getEconomy() {
        return econ;
    }


    @Override
    public void onDisable() {
        log("Пока пупсики!");
    }
}

我修好了!不知道怎么做,但它现在可以工作了!谢谢大家!

java jar noclassdeffounderror bukkit spigot

评论

0赞 vivek 8/9/2023
你在遗忘的罐子里看到那个类了吗?
0赞 Timas_bro 8/9/2023
是的,它就在这里,在 mc.obliviate.inventory.Gui 中
0赞 g00se 8/9/2023
Megabox_clans插件;没有它,我们就无法进行测试。你确实需要提供一个最小的可重现示例,但如果该类可以做到这一点,那么你可以发布它
0赞 Timas_bro 8/9/2023
我把它加@g00se
4赞 Mark Rotteveel 8/10/2023
“即使是GPT也帮不上忙。”那是因为 ChatGPT 只不过是一个令人信服的废话生成器。它可以生成漂亮的文本,但很多时候它只是想出看似合理的胡说八道,而不是真正基于现实的东西(或者它可能一只脚踩在地上,另一只脚在仙境)。

答: 暂无答案