How To: Deploy Java Telegram Bot to Heroku – Telegram 简体版

Haley

How To: Deploy Java Telegram Bot to Heroku

Hello! Welcome to my guide on deploying your java telegram bot onto Heroku. Deploying your bot onto a server allows you to have your bot up and running 24/7. This guides requires you to have a java telegram bot. Follow this guide to create one.

Let’s begin.

1. Sign up on Heroku

Click this link: here to sign up for a free Heroku account. Check your inputted email to confirm your Heroku account.

2. Create new Application

Login to your Heroku account. Navigate to your dashboard. Currently, you do not have any apps yet. So, click “Click New App” button. Input a meaningful name for your new app. Next, choose a suitable Region and confirm “Create App”

3. Understanding Heroku CLI and Dynos

For this next step, we will need to understand how Heroku is able to integrate with your java program. Thankfully, Heroku provides us with concise and clear documentation on how it works and what to do. Click here and understand how to run non-web java dynos on Heroku.

Understanding this is crucial to your deployment phase.

4. Edit pom.xml File

Now, navigate to your pom.xml file. This pom.xml file is a very important file for Maven. It contains information about the project and various configuration detail used by Maven to build the project. Reference this <build> code into your own code.

Code in <build>

5. Create Procfile

A Procfile will help to declare how you want your application to be executed. To create a Procfile, open up your NotePad and Type: worker: sh target/bin/workerBot

It is important that your Procfile does not have any file extensions. To do this successfully, Save your Procfile under All Files and add double quotes to the procfile file name, like this: “Procfile”. This file should be saved in your java project’s root directory.

For more information, you can refer to this link.

6. Installing Maven and Building Your Application

In your command prompt, go to your project’s directory. Next, we will download Maven with this command “mvn clean install”. And after this, input this command “mvn package” to build the application.

To test the success of the installation, run “mvn -v”.

7. Download Heroku CLI

The next important step in this deployment is downloading the Heroku Command Line Interface (CLI). This is crucial because you will be running commands in the command line to login into heroku and deploying your application from the command line. Click the download link here.

After that, you’re set to login into heroku from your command line. Simply go to your project directory again and run “heroku login”. Check out Heroku’s documentation in deploying with Git with this link. Alternatively, you can go back to your browser where you created your heroku app in Step 2. Follow the instructions on Git to push your git repo onto heroku’s server under your account.

Finally, if you are able to run “heroku ps: scale worker=1”, you have successfully deployed your java application! Your telegram bot is now on the server running 24/7.

Since your program is running on heroku’s server, you can no longer see your print statements. You can run ‘heroku run “sh target/bin/workerBot”’ to view your print statements in real time.

Final Words

Congratulations on reaching this stage. You have successfully deployed your java telegram bot. I hope I have helped in your bot’s journey. Thank you for reading and following along.

Here are some pointers if you are stuck in any of these steps.

Error 1

If the error you’re facing when installing maven is that JAVA HOME is not properly using JDK, you can solve this by adding JAVA_HOME into your System Variables. Go to Windows search and type “View Advanced System settings”, then click “Environment Variables”. Under System Variables, click NEW and type JAVA_HOME for the name and its location link. Mine is: C:\Program Files\Java\jdk-15.0.1.

Finally, click Path and add this ‘%JAVA_HOME%/bin’. Restart your computer and the changes should be updated.

Error 2

In my deployment, I faced a problem with heroku buildpacks. If you face a similar issue, clear all the buildpacks in your heroku server and add the java buildpack. Run these commands in your project’s directory, ‘heroku buildpacks:clear’ and ‘heroku buildpacks:set heroku/java’. This should solve the problem.

Ten articles before and after

Telegram Pc多开/双开,Telegram 桌面版 for Windows 便携版 -Telegram 简体版

Делаем бота для учета личных расходов на Python используя Google Spreadsheets – Telegram 简体版

16:37 Time | Conversion and Information | – Telegram 繁体版 下载

22:40 Time | Conversion and Information | – Telegram 繁体版 下载

18:42 Time | Conversion and Information | – Telegram 繁体版 下载

Create your beautiful sticker pack in Telegram using Figma – Telegram 简体版

如何打开 Telegram 电报开发者模式? | – Telegram 简体版

Crowny Twitter & Telegram Contest – Telegram 官网下载

10003 Hours to Days | Telegram Web

10233 Hours to Days | Telegram Web

About Me

Pretium lorem primis senectus habitasse lectus donec ultricies tortor adipiscing fusce morbi volutpat pellentesque consectetur risus curae malesuada dignissim lacus convallis massa mauris.