如何让Heroku找到并加载我的主Java文件

huangapple go评论86阅读模式
英文:

How do I get Heroku to find and load my main java file

问题

当我尝试部署我的Discord机器人程序时,没有任何反应,日志显示如下:
Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8

Error: 找不到或无法加载主类 src.main.java.Main.java

我的Procfile位于代码库的根目录,并且包含以下代码行:
Worker: java src/main/java/Main.java

我按照YouTube上的教程操作,以在Heroku上运行自己的Discord机器人,并且我完美地复制了所有内容。在IntelliJ中,完全相同的项目可以无错误运行。
我该如何让Heroku找到并加载我的程序?

英文:

When I try to deploy my discord bot program nothing happens and the logs say this:
Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8

Error: Could not find or load main class src.main.java.Main.java

My Procfile is in the root of the repository and it has this line of code:
Worker: java src/main/java/Main.java

I was following a youtube guide on how to get my own discord bot running on Heroku and I copied everything perfectly. The exact same project runs with no errors in IntelliJ.
How do I get Heroku to find and load my program?

答案1

得分: 0

你正在尝试运行一个Java源文件(.java扩展名),而不是已编译的类文件。你还没有指定Java应该在哪里搜索类的类路径。

你的Procfile应该类似于:
worker: java -cp target/classes Main

这将在Maven保存已编译类文件的target/classes目录中查找Main类。如果你使用不同的构建工具,目录会有所不同。上述命令在类路径中也没有包含你的依赖项。

仍然假设你正在使用Maven,你可以使用Maven的依赖插件将你的依赖项复制到一个目录,并在Procfile中的-cp参数中包含该目录。

英文:

You're trying to run a Java source file (.java extension), not a compiled class file. You're also not specifying a classpath where Java should search for classes.

Your Procfile should have something like:
worker: java -cp target/classes Main

This will look for the Main class in target/classes where Maven saves compiled class files. If you use a different build tool, the directory is different. The above command also does not include your dependencies in the classpath.

Still assuming you're using Maven, you can use Maven's dependency plugin to copy your dependencies to a directory and include that directory in the -cp argument within the Procfile.

huangapple
  • 本文由 发表于 2020年10月26日 14:12:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/64532243.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定