Ali Bdeir
Ali Bdeir

Reputation: 4375

Heroku 503 error

Heroku is crashing with no direct error message. Here's the logs:

2017-02-20T18:27:08.194304+00:00 app[web.1]: Hello World
2017-02-20T18:27:08.512366+00:00 heroku[web.1]: State changed from starting to crashed
2017-02-20T18:27:08.489335+00:00 heroku[web.1]: Process exited with status 0
2017-02-20T18:27:09.590397+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=x.herokuapp.com request_id=59533920-38d9-426f-a7e0-c32d667b8d49 fwd="94.187.7.67" dyno= connect= service= status=503 bytes=
2017-02-20T18:27:10.538493+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=x.herokuapp.com request_id=30fdd320-7ea6-4eb5-b3fa-8cf8c4240a21 fwd="94.187.7.67" dyno= connect= service= status=503 bytes=

Nothing changes with heroku logs -n 1000 Here's my code:

public class Main {

public static void main(String[] args){
    System.out.println("Hello World");
  }

}

Procfile:

web: java -jar build/libs/app-name-1.0-SNAPSHOT.jar

Build.gradle:

version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.5

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
    }
}

repositories {
    mavenCentral()
}

task stage(dependsOn: ['build', 'clean'])
build.mustRunAfter clean

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

jar {
    manifest {
        attributes(
                'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
                'Main-Class': com.mypackage.Main
        )
    }
}
apply plugin: 'com.github.johnrengelman.shadow'

I can see that Hello World is being printed. But why is it crashing afterwards?

I am using Gradle with IntelliJ IDEA

Upvotes: 1

Views: 2491

Answers (1)

Oleg Kurbatov
Oleg Kurbatov

Reputation: 1386

The problem here is the application is not a web application.

Consider the content of the Procfile:

web: java -jar build/libs/app-name-1.0-SNAPSHOT.jar

The first word is web which suggests to Heroku that you try to deploy a web application. But the application is not a web application according to its code:

public class Main {

    public static void main(String[] args){
        System.out.println("Hello World");
    }

}

The application doesn't run any web server awaiting an HTTP connection on 80 or 8080 port. The application just prints "Hello World" to the standard output and exits (because the end of program reached).

2017-02-20T18:27:08.489335+00:00 heroku[web.1]: Process exited with status 0

The web application is suposed to be waiting for incomming connections. It must not reach the end unless a human stops it.

You can generate a template of a web application using this generator. The application will use embedded apache tomcat (that will act as the web server of the application) and spring-boot to bootstrap the web application infrastructure. Here is short tutorial on how to write Hello World application on spring-boot. It deploys and works on Heroku.

Upvotes: 3

Related Questions