0

new user here! I know there's similar questions with answers to this, but I don't know how to apply them to my case, so sorry if it's repetitive!

So... I'm trying to make my first bot for Telegram and I've decided to use Java. I'm following this tutorial and copypasted the code from the two example classes (EchoBot and Main). The only thing I changed is the token with the token I got from the BotGodfather on Telegram. I'm using Eclipse on Ubuntu 18.04.1 as IDE so I started by making a Java project and then configured it as a Maven project. This is the code of my pom.xml: `

    <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>EchoBot</groupId>
  <artifactId>EchoBot</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>EchoBot</name>
  <dependencies>
    <dependency>
     <groupId>org.telegram</groupId>
     <artifactId>telegrambots</artifactId>
     <version>3.6.1</version>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <release>10</release>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

`

When I run the program I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Module at org.telegram.telegrambots.ApiContext.getInjector(ApiContext.java:46) at org.telegram.telegrambots.ApiContext.getInstance(ApiContext.java:25) at org.telegram.telegrambots.bots.TelegramLongPollingBot.(TelegramLongPollingBot.java:17) at pearlbot.EchoBot.(EchoBot.java:8) at pearlbot.Main.main(Main.java:17) Caused by: java.lang.ClassNotFoundException: com.google.inject.Module at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ... 5 more

What could the problem be? Keep in mind that I don't even know what Maven is, so if it's something related to it, you'll need to explain what's wrong as if you were talking to a child! ^^''

3
  • 1
    run mvn clean install, it will put necessary jars to your classpath.
    – mstfyldz
    Mar 8, 2019 at 10:48
  • 1
    You might be missing a dependency in your pom. For a big part (but not exclusively) maven is a dependency management tool. It makes sure that what you need for libraries is on your path. Apparently, it misses a library.
    – Stultuske
    Mar 8, 2019 at 10:51
  • Ok, it worked! Thanks! :D
    – M.I.Zu
    Mar 8, 2019 at 11:21

1 Answer 1

1

I got this error when i try to install testng for eclipse Version: 2019-12 (4.14.0) and run the program then i got this error. Finally i got fixed -

Eclipse IDE for Java Developers, Version: 2019-12 (4.14.0), Build id: 20191212-1212. TestNG 7.1.0.r202001120626

Removing the TestNG library from the build path of the project containing the test and installing TestNG from menu Help / Install New Software did not work for me, I kept getting this error.

What worked for me was downloading guice-4.2.2.jar (from https://github.com/google/guice/wiki/Guice422), copying it into any folder, and adding it to the build path of the project as external JAR.

From Eclipse, Go to Help > Install software or You can install from market place as well (Help > Market Place). After installing TestNG from market place, it dint work, but installing the GUICE422.jar to the build path worked for me So make sure after installing TestNG from market place, install the Guice422 Jar file as well link to install testng from eclipse market place

This worked for me --- Hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.