英文:
Deployed discord bot on heroku, bot won't come online
问题
我查看了以前的帖子,但我不太理解它们(也许我很笨)。其中有一条建议设置一个 procfile,如下所示:
worker: java $JAVA_OPTS -jar <JAR_FILE_PATH>
但我不知道那个文件路径是什么。我按照 Heroku 的文档来做,想知道如何让 Discord 机器人上线。
目前,它是通过命令提示符行部署的,命令是 "heroku:deploy-war",作为 IntelliJ 中的 Maven 运行。
这是我的 Procfile 内容:worker: java $JAVA_OPTS -jar target\Disbot-1.0-SNAPSHOT.jar
总的来说,这只是一个非常复杂的方式来问 "在 Heroku 中做这件事时 jar 文件路径是什么?"
如果有更好的方法来做这个,或者有更有效的方式,我很乐意尝试。如果需要额外的信息,我会尽量提供。
英文:
I've looked at previous posts, but I don't quite understand them (maybe I'm stupid). One of them advised to a procfile set up as so
worker: java $JAVA_OPTS -jar <JAR_FILE_PATH>
but I don't know what that file path would be. I followed the Heroku docs to get this and am wondering how to get the discord bot online.
Currently, its being deployed with a command prompt line "heroku:deploy-war" as a maven run in intelliJ
Heres my procfile:worker: java $JAVA_OPTS -jar target\Disbot-1.0-SNAPSHOT.jar
All in all, this is just a really overcomplicated way to ask "what is the jar file path when doing this thing in heroku?"
If there's a better way to do this or a much more effective way I would be glad to try it out. If additional information is requested, I will provide it if possible.
答案1
得分: 1
由于Heroku在一个随机的/tmp
目录中生成了target
目录,在此答案发布时(2021-09-18),当前的答案不起作用,因此我按照Heroku文档中的步骤进行操作,使用了以下项目结构:
.
├─ pom.xml
├─ Procfile
└─ src
└─ main
└─ java
└─ com
└─ example
└─ Main.java
- 在
pom.xml
中添加以下构建依赖:
<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>com.example.Main</mainClass>
<name>main</name>
</program>
</programs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
-
添加
Procfile
文件,其中包含指令:worker: sh target/bin/main
-
提交更改并推送到Heroku的远程仓库。
-
扩展Dyno以防止其进入休眠状态(请考虑您的项目有最大工作时间限制):
heroku ps:scale worker=1
英文:
Due to Heroku generating the target
directory in a random /tmp
, The current answer is not working at the time of this answer (2021-09-18), so I followed these steps from the Heroku documentation, using this project structure:
> .
> ├─ pom.xml
> ├─ Procfile
> └─ src
> └─ main
> └─ java
> └─ com
> └─ example
> └─ Main.java
- Added this build dependency to
pom.xml
:
> <build>
> <plugins>
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>appassembler-maven-plugin</artifactId>
> <version>1.1.1</enter code hereversion>
> <configuration>
> <assembleDirectory>target</assembleDirectory>
> <programs>
> <program>
> <mainClass>com.example.Main</mainClass>
> <name>main</name>
> </program>
> </programs>
> </configuration>
> <executions>
> <execution>
> <phase>package</phase><goals><goal>assemble</goal></goals>
> </execution>
> </executions>
> </plugin>
> </plugins>
> </build>
- Added the
Procfile
with this instruction:worker: sh target/bin/main
- Committed the changes and pushed to Heroku's remote.
- Scaled the dyno so it doesn't go to sleep (take into account that you have a maximum amount of hours for your projects):
heroku ps:scale worker=1
答案2
得分: 0
已解决该问题 - 更确切地说,找到了一个解决方法。将其打包为 .jar 文件,并意识到 Procfile 实际上只是一个命令提示符的东西。将带有文本 worker: java -jar Jar.jar 的 Procfile 将该 jar 文件上传到 GitHub。尽管我没有得到答案,还是要感谢任何花时间查看这个问题的人。
英文:
Solved the issue - well more found a workaround. Packaged it as a .jar file and realized the Procfile was really just a command prompt thing. Uploaded the jar onto GitHub with the Procfile, that had the text worker: java -jar Jar.jar. Even though I didn't get an answer, thanks to anyone who took some time to look at this question
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论