Search code examples
javaherokudiscorddiscord-jda

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


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?


Solution

  • 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.