Closed drunckoder closed 7 years ago
Have tried building with Maven and everything launches ok. I've also updated Gradle version to 3.1 and the issue is still there.
I never tried Gradle with this project, can you post here the content of your build.gradle file?
Here it is:
group 'com.drunckoder'
version '1.0-SNAPSHOT'
apply plugin: 'java'
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile ('org.telegram:telegrambots:2.4.0')
}
jar {
manifest {
attributes "Main-Class": "com.drunckoder.m214bot.Launcher"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
task stage {
dependsOn build
}
I've made a sample project with this build.gradle
and it seems to build correctly:
group 'your.group.id'
version '1.0'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.telegram', name: 'telegrambots', version: '2.4.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
jar {
manifest {
attributes "Main-Class": "your.main.class"
}
}
Can you give it a try?
Thanks for your reply. I've tried to build with your build.gradle file, and I got no errors either, as I expected. The problem appears, after launching the project, I'm getting an exception like in my first post:
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:331)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:311)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:337)
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:163)
at org.telegram.telegrambots.updatesreceivers.Webhook.startServer(Webhook.java:53)
at org.telegram.telegrambots.TelegramBotsApi.<init>(TelegramBotsApi.java:68)
at my.group.id.Launcher.main(Launcher.java:17)
Here's my code:
package my.group.id;
import org.telegram.telegrambots.TelegramBotsApi;
import org.telegram.telegrambots.api.methods.BotApiMethod;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.TelegramWebhookBot;
import org.telegram.telegrambots.exceptions.TelegramApiException;
/**
* Created by drunckoder on 10/9/16
*/
public class Launcher extends TelegramWebhookBot {
public static void main(String[] args) {
try {
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(
"/etc/ssl/certs/ca-certificates.crt",
"",
"https://example.com:443/",
"http://0.0.0.0:5000/"
);
telegramBotsApi.registerBot(new Launcher());
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
public BotApiMethod onWebhookUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasText()) {
SendMessage sendMessage = new SendMessage();
sendMessage.setChatId(update.getMessage().getChatId().toString());
sendMessage.setText("Well, all information looks like noise until you break the code.");
return sendMessage;
}
return null;
}
public String getBotUsername() {
return "mybotusernamewashere";
}
public String getBotToken() {
return "mybottokenwashere";
}
public String getBotPath() {
return "";
}
}
Adding a couple of screenshots, hoping them to clarify things going on here:
Wondering, are you using Java EE?
Nope. Java SE.
Not sure what's going on, can you join our supergroup in Telegram to discuss it?
Issue dissapeared since some version
I'm getting an exception after launching a webhook bot built using gradle:
Exception in thread "main" java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map; at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:331) at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:311) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.<init>(GrizzlyHttpContainer.java:337) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:163) at org.telegram.telegrambots.updatesreceivers.Webhook.startServer(Webhook.java:53) at org.telegram.telegrambots.TelegramBotsApi.<init>(TelegramBotsApi.java:68) at com.drunckoder.m214bot.Launcher.main(Launcher.java:22) 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.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
It seems to be some a conflict in dependecies. I've found a way to prevent generation of this exception by excluding
com.sun.jersey:jersey-bundle
:compile ('com.github.rubenlagus:TelegramBots:v2.4.0') { exclude group: 'com.sun.jersey' exclude module: 'jersey-bundle' }
But this appears to mess everything up: bot simply doesn't respond to requests.
com.github.rubenlagus:TelegramBots:v2.4.0 is the only dependency in my project.
My gradle version:
`------------------------------------------------------------
Gradle 2.10
Build time: 2016-01-26 15:17:49 UTC Build number: none Revision: UNKNOWN
Groovy: 2.4.5 Ant: Apache Ant(TM) version 1.9.6 compiled on July 8 2015 JVM: 1.8.0_92 (Oracle Corporation 25.92-b14) OS: Linux 4.7.2-040702-generic amd64 `
Please tell me, if I'm doing something wrong. Thanks!