I'm writing a telegram bot by this lib: https://github.com/rubenlagus/TelegramBots .
The bot can run successfully on my local machine but cannot run on Heroku. The Error Message is "Counld not find or load main class."
I have read a lot of similar questions but still cannot solve my problem because other questions have some differences from this.
Here are some logs when the error happened on Heroku:
2021-05-12T11:51:15.644410+00:00 heroku[worker.1]: Starting process with command `sh target/bin/my_bot_test`
2021-05-12T11:51:17.945513+00:00 heroku[worker.1]: State changed from starting to up
2021-05-12T11:51:19.427171+00:00 app[worker.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-05-12T11:51:19.616191+00:00 app[worker.1]: Error: Could not find or load main class Main
2021-05-12T11:51:19.668857+00:00 heroku[worker.1]: Process exited with status 1
2021-05-12T11:51:19.756822+00:00 heroku[worker.1]: State changed from up to crashed
Here is the content of pom.xml
:
<?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>
<groupId>org.example</groupId>
<artifactId>my_bot_test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambots-abilities</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs>
<program>
<mainClass>Main</mainClass>
<name>my_bot_test</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here are some cmds are used for deploy:
mvn clean install
git add .
git commit -m "test"
heroku login
git remote add heroku [gitUrl]
git push heroku master
heroku ps:scale worker=1
I referred to this page when studying: https://javarush.ru/groups/posts/504-sozdanie-telegram-bota-na-java-ot-idei-do-deploja
The Procfile I wrote this:
worker: sh target/bin/my_bot_test
I learned that the content of Procfile
means excute command target/bin/my_bot_test
in the root directory of project. So I try to excute it on my machine and it runs successfully.
I don't how the error happened and how to solve the problem... Please help me. Thanks in advance.