@aquapendente

Как исправить ошибку java.lang.NoClassDefFoundError: org/telegram/telegrambots/bots/TelegramLongPollingBot?

Всем привет! Я пишу бота для телеграма на java и встраиваю его в свой bungeecord плагин. Использую библиотеку telegrambots самой последней версии (6.1.0). При запуске скомпилированного .jar файла я получаю вот такую ошибку:
spoiler
java.lang.NoClassDefFoundError: org/telegram/telegrambots/bots/TelegramLongPollingBot
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at net.md_5.bungee.api.plugin.PluginClassloader.loadClass0(PluginClassloader.java:44)
at net.md_5.bungee.api.plugin.PluginClassloader.loadClass(PluginClassloader.java:37)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.fcauthbungee.mc.fcauthbungee.Main.onEnable(Main.java:83)
at net.md_5.bungee.api.plugin.PluginManager.enablePlugins(PluginManager.java:250)
at net.md_5.bungee.BungeeCord.start(BungeeCord.java:309)
at net.md_5.bungee.BungeeCordLauncher.main(BungeeCordLauncher.java:43)
at net.md_5.bungee.Bootstrap.main(Bootstrap.java:15)
Caused by: java.lang.ClassNotFoundException: org.telegram.telegrambots.bots.TelegramLongPollingBot
at net.md_5.bungee.api.plugin.PluginClassloader.loadClass0(PluginClassloader.java:63)
at net.md_5.bungee.api.plugin.PluginClassloader.loadClass(PluginClassloader.java:37)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 18 more

Я пробовал запустить его на версиях 3.5, 3.6, 3.6.1, но ошибка не пропадала.
Вот мой код:
Bot.java

public class Bot extends TelegramLongPollingBot {
    private Main plugin;

    public void main(String[] args) throws TelegramApiException {
        TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class);
        try {
            telegramBotsApi.registerBot(new Bot());
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
        this.saveDefaultConfig();
    }

    private Configuration config;

    public void saveDefaultConfig() {
        try {
            File bot_dir = new File(plugin.getDataFolder() + File.separator + "bot");
            bot_dir.mkdir();

            File file = new File(bot_dir, "bot_config.yml");
            if (!file.exists()) {
                Files.copy(plugin.getResourceAsStream("bot_config.yml"), file.toPath(), new CopyOption[0]);
            }
            this.loadConfig();
        } catch(IOException ignore) {}
    }

    public void reloadConfig() {
        this.loadConfig();
    }

    private void loadConfig() {
        try {
            this.config = ConfigurationProvider.getProvider((Class) YamlConfiguration.class).load(new File(plugin.getDataFolder() + File.separator + "bot", "bot_config.yml"));
        } catch (IOException ignore) {}
    }

    public Configuration getConfig() {
        return this.config;
    }


    public void sendMsg(Message message, String text) {
        SendMessage sendMessage = new SendMessage();
        sendMessage.enableMarkdown(true);

        sendMessage.setChatId(message.getChatId().toString());
        sendMessage.setReplyToMessageId(message.getMessageId());
        sendMessage.setText(text);

        try {
            setButtons(sendMessage);
            execute(sendMessage);
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }


    public void onUpdateReceived(Update update) {
        Model model = new Model();
        Message message = update.getMessage();
        if (message != null && message.hasText()) {
            switch (message.getText().split(" ")[0].toLowerCase()) {
                case "/help":
                    sendMsg(message, getConfig().getString("messages.helpCommand"));
                    break;
            }
        }

    }


    public void setButtons(SendMessage sendMessage) {
        ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
        sendMessage.setReplyMarkup(replyKeyboardMarkup);
        replyKeyboardMarkup.setSelective(true);
        replyKeyboardMarkup.setResizeKeyboard(true);
        replyKeyboardMarkup.setOneTimeKeyboard(false);

        List<KeyboardRow> keyboardRowList = new ArrayList<>();
        KeyboardRow keyboardFirstRow = new KeyboardRow();

        keyboardFirstRow.add(new KeyboardButton("/help"));
        keyboardFirstRow.add(new KeyboardButton("/setting"));

        keyboardRowList.add(keyboardFirstRow);
        replyKeyboardMarkup.setKeyboard(keyboardRowList);

    }

    public String getBotUsername() {
        return "fcauth_bot";
    }

    public String getBotToken() {
        return "5711670647:AAH7P4qo_j0UaJpeJZmUOzxjqTxMVs24gWM";
    }
}


Вот такая у меня dependency в pom.xml:
<dependency>
    <groupId>org.telegram</groupId>
    <artifactId>telegrambots</artifactId>
    <version>6.1.0</version>
</dependency>
  • Вопрос задан
  • 536 просмотров
Решения вопроса 1
xez
@xez Куратор тега Java
TL Junior Roo
Эта ошибка о том, что джава не может найти библиотеку в classpath.
Варианты решения:
1. Добавить параметр запуска: java -cp {путь до библиотеки}
Мавен, кстати, умеет складывать все нужные зависимости в /target
2. Собрать «fat-jar» артефакт, включающий сразу все зависимости.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Хабаровск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽