rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.77k stars 1.22k forks source link

Can't execute a bot .jar file from the terminal (ubuntu) #858

Closed itai590 closed 3 years ago

itai590 commented 3 years ago
user@laptop:~ $ java -jar bot.jar
Exception in thread "main" java.lang.NoSuchMethodError: 'void org.telegram.telegrambots.meta.TelegramBotsApi.<init>(java.lang.Class)'
        at mybot.MainClass.main(MainClass.java:14)

import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;

public class MainClass {

    public static void main(String[] args) {
        try {
            TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class); //line 14
            telegramBotsApi.registerBot(new mybot());
        } catch (TelegramApiException e) {
            e.printStackTrace();
        }
    }
Chase22 commented 3 years ago

The jar you've build is missing its dependencies. You either have to build a fat-jar or tell the Java runtime where the dependencies are

itai590 commented 3 years ago

I managed to fix it Thank you

Chase22 commented 3 years ago

Great then please close the issue @itai590