Answer the question
In order to leave comments, you need to log in
Why is the .jar not being run from the console?
When I try to run the Main class java Main
or run a .jar file , I get an errorjava -jar Bot-1.jar
Error: Unable to initialize main class Main
Caused by: java.lang.NoClassDefFoundError: org/telegram/telegrambots/meta/exceptions/TelegramApiRequestException
<?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>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<archive>
<manifest>
<mainClass>Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<groupId>TestBot</groupId>
<artifactId>Bot</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>4.9.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.16</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
</properties>
</project>
Answer the question
In order to leave comments, you need to log in
Through Idea, this all works because when it starts, it carefully writes the path to the necessary libraries in the classpath. All these libraries are obviously downloaded automatically and are present in the local cache (folder ~/.m2).
You need to either build "fat jar" aka jar-with-dependencies,
or carry all the necessary libs with you and add them to the classpath at startup.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question