3

I'm trying to use Heroku with Java, I have this directory structure and I'm using IntelliJ:

target
  com
    x
     y
      Main.java

in the procfile:

web: java -cp target/classes/;target/dependency/* com.x.y.Main

When I try heroku local web I get " Could not find or load main class com.x.y.Main "

However, it is there. I'm using Windows.

Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117

1 Answers1

3

Java classpath separator is platform dependent, ; for Windows and : for Unix.

If you are trying to run heroku local on Windows, your command will fail with exactly the message you posted. Replacing it with:

web: java -cp target/classes/;target/dependency/* com.x.y.Main

will make it run on Windows.

If you get this error with the app deployed in the cloud (which is Unix), then there is no com.x.y.Main class in the target/classes directory. You can verify that by running heroku run bash followed by ls -lR and checking the directory/files layout on the server.

If you run on Windows ensure to run mvn clean install to compile the sources into target/classes directory.

For Gradle based projects you would need to adjust the classpath since it uses the different layout (build/classes) or the jar file in build/libs, see the guide for the details:

web: java -jar build/libs/myprojectname-1.0-SNAPSHOT.jar

To make it work in cloud and on Windows without changing Procfile every time, create Procfile.windows with web: java -cp target/classes/;target/dependency/* com.x.y.Main and start the app using heroku local web -f Procfile.windows command locally.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904