8

I have my main class:

public class Main {

    public static void main(String[] args){
        Spark.port(getHerokuAssignedPort());
        get("/hello", (req, res) -> "Hello Heroku World");
    }



    private static int getHerokuAssignedPort() {
        ProcessBuilder processBuilder = new ProcessBuilder();
        if (processBuilder.environment().get("PORT") != null) {
            return Integer.parseInt(processBuilder.environment().get("PORT"));
        }
        return 4567; //return default port if heroku-port isn't set (i.e. on localhost)
    }

}

My procfile:

web: java -jar build/libs/CrowdSubhaHeroku-1.0-SNAPSHOT-all.jar

Note: I'm using shadowJar since a normal jar creation doesn't include dependencies I need such as Spark and Firebase.

Now, if I do:

heroku local web

And go to localhost:5000, I get a 404 error. However, the application doesn't actually crash. It stays running.

That is unlike when I do:

heroku open

After a git add ., git commit -m "x", and a git push heroku master

Which crashes with an "Application Error" and gives me this ONLY:

2017-02-23T15:18:18.848727+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=crowdsubha.herokuapp.com request_id=ce636951-862e-4b2f-a698-924db3039a07 fwd="94.187.7.67" dyno= connect= service= status=503 bytes=
2017-02-23T15:18:20.022743+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=myapp.herokuapp.com request_id=d1e9ec86-ffe4-4a09-9934-81e25378c32c fwd="94.187.7.67" dyno= connect= service= status=503 bytes=

Those are the only errors I got. The previous errors are the logs from yesterday.

I'm not exactly sure what's the problem. I suspect it has something to do with the shadowJar. But I'm not sure.

Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
  • Can you try running `heroku logs -t` and leave it running. Then in another terminal session run `heroku ps:restart`? If you see an error message, please add it here. – codefinger Feb 24 '17 at 16:57
  • Apparently, my Jar file (my-app-name-snapshot-1.0-all.jar) is not being deployed to heroku. Which I verified using `heroku run ls build/libs/`. However, the regular jar file is being deployed. But the regular jar file doesn't contain the gradle dependencies for some reason, and I can't use Spark if I'm using the regular jar – Ali Bdeir Feb 25 '17 at 08:23
  • Does the jar file exist locally when you run `./gradlew clean stage`? – codefinger Feb 27 '17 at 16:05

1 Answers1

3

I found out what's the problem. I had to change my build method from gradlew clean stage when deploying to Heroku with git push Heroku master to gradlew shadowJar.

How I did it is mentioned in the docs:

Heroku config:set GRADLE_TASK="shadowJar"

Now, every time to do a git push Heroku master, it doesn't run gradlew clean stage, but gradlew shadowJar, which I use to include dependencies into my Java web application.

BehrouzMoslem
  • 9,053
  • 3
  • 27
  • 34
Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117