heroku error: Could not find or load main class

Viewed 286

I've created a simple app that uses gradle and maven, and i'm trying to run it on heroku. The build completes successfully, but the app crashes immediately afterwards.

2020-05-16T01:54:59.000000+00:00 app[api]: Build succeeded
2020-05-16T01:55:03.088181+00:00 heroku[worker.1]: State changed from starting to up
2020-05-16T01:55:04.411587+00:00 heroku[worker.1]: State changed from up to crashed
2020-05-16T01:55:04.216434+00:00 app[worker.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-05-16T01:55:04.331808+00:00 app[worker.1]: Error: Could not find or load main class <classname>

My procfile contains this:

worker: java -jar target/<jarname>.jar

Another thing I've found which could be a problem is the directory for my main class- I didn't give it a group when i created the project so it's Directory is:

src\main\Main.java

Could this be a problem?

1 Answers

The error message is pretty clear... "Could not find or load main class" Apparently, none of your class files contain a public static void main(String[] args) method signature, so Heroku has no entry point to start your project.

The JVM needs to see a main method with that exact signature. main is just a convention that lets the JVM know where the initial entry point is to execute your code. public has to be there for the sake of access, and static allows main to be called without having created an instance of whatever object includes the main method.

Related