简体   繁体   中英

Heroku java app crashes: Web process failed to bind to $PORT

I am trying to deploy a java app using gradle and am able to do all the steps of deployment however when i write heroku open after deploying the screen stays white for a while then the logs return the error

2022-10-10T05:52:17.000000+00:00 app[api]: Build succeeded
2022-10-10T05:53:40.640805+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2022-10-10T05:53:40.718527+00:00 heroku[web.1]: Stopping process with SIGKILL
2022-10-10T05:53:40.842261+00:00 heroku[web.1]: Process exited with status 137
2022-10-10T05:53:40.890653+00:00 heroku[web.1]: State changed from starting to crashed

My procfile is configured as so

web: java $JAVA_OPTS -Dserver.port=$PORT -jar app/build/libs/app-all.jar

My build.gradle

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java application project to get you started.
 * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
 * User Manual available at https://docs.gradle.org/7.4/userguide/building_java_projects.html
 */

plugins {
    // Apply the application plugin to add support for building a CLI application in Java.
    id 'application'  
}



jar {
  manifest {
    attributes(
      'Main-Class': 'group5MentorMatcher.Main',
    )
  }
}

task fatJar(type: Jar) {
  duplicatesStrategy = DuplicatesStrategy.EXCLUDE
  manifest.from jar.manifest
  classifier = 'all'
  from {
    configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
  } {
    exclude "META-INF/*.SF"
    exclude "META-INF/*.DSA"
    exclude "META-INF/*.RSA"
    exclude "META-INF/*.TXT"
  }
  with jar
}

repositories {
    // Use Maven Central for resolving dependencies.
    mavenCentral()
}

dependencies {
    //Dependencies for testing
    def junitVer = "5.8.2";
    testImplementation group: "org.junit.jupiter", name: "junit-jupiter-api", version: junitVer;
    testRuntimeOnly group: "org.junit.jupiter", name: "junit-jupiter-engine", version: junitVer;
    testImplementation group: "org.hamcrest", name: "hamcrest", version: "2.2";

    // Use JUnit Jupiter for testing.
    testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'

    // This dependency is used by the application.
    implementation 'com.google.guava:guava:30.1.1-jre'
    
    // Use postgres to connect to the database
    implementation 'org.postgresql:postgresql:42.4.0'

    // guava
        implementation group: 'com.google.guava', name: 'guava', version: '30.1.1-jre'

    // jooby
    def joobyVer =  '2.13.0'
    implementation group: 'io.jooby', name: 'jooby-netty', version: joobyVer
    implementation group: 'io.jooby', name: 'jooby-gson', version: joobyVer
    implementation group: 'io.jooby', name: 'jooby-swagger-ui', version: joobyVer

    //logging
        implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
        implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.10'

        implementation group: 'com.zaxxer', name: 'HikariCP', version: '4.0.3'
        implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.5'

        def jdbiVer = '3.21.0'
        implementation group: 'org.jdbi', name: 'jdbi3-core', version: jdbiVer
        implementation group: 'org.jdbi', name: 'jdbi3-sqlobject', version: jdbiVer
}

application {
    // Define the main class for the application.
    mainClass = 'group5MentorMatcher.Main'
}

//test {
//    useJUnitPlatform();
//    onlyIf { project.gradle.startParameter.taskNames.contains("test") }
//}

//tasks.named('test') {
    // Use JUnit Platform for unit tests.
 //   useJUnitPlatform()
//}



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

task copyToLib(type: Copy) {
    from configurations.compileClasspath
    into 'build/libs'
}

stage.dependsOn(copyToLib)

gradle.taskGraph.whenReady {
  taskGraph ->
    if (taskGraph.hasTask(stage)) {
      test.enabled = false
    }
}
artifacts {
    archives fatJar
}

sourceSets {
    'static' {
        resources {
            srcDirs = ['static']
        }
        java{
            srcDirs = []
        }
    }
}

and finally my Main class

/*
 * This Java source file was generated by the Gradle 'init' task.
 */
package group5MentorMatcher;

import dao.JDBIDaoFactory;
import dao.MatchDAO;
import dao.MenteeDAO;
import dao.MentorDAO;
import dao.PersonDAO;
import dao.PostgradCourseDAO;
import dao.PostgraduateExperienceDAO;
import dao.UndergradCourseDAO;
import dao.UndergraduateExperienceDAO;
import io.jooby.Jooby;
import io.jooby.OpenAPIModule;
import io.jooby.ServerOptions;
import io.jooby.json.GsonModule;
import java.nio.file.Paths;
import java.sql.*;
import module.MatchModule;
import module.MenteeModule;
import module.MentorModule;
import module.PersonModule;
import module.PostgradCourseModule;
import module.PostgraduateExperienceModule;
import module.UndergradCourseModule;
import module.UndergraduateExperienceModule;

public class Main extends Jooby {

    private final PersonDAO personDAO = JDBIDaoFactory.getPersonDAO();
    private final MentorDAO mentorDAO = JDBIDaoFactory.getMentorDAO();
    private final MenteeDAO menteeDAO = JDBIDaoFactory.getMenteeDAO();
    private final MatchDAO matchDAO = JDBIDaoFactory.getMatchDAO();
    private final UndergraduateExperienceDAO undergraduateDAO = JDBIDaoFactory.getUndergraduateExperienceDAO();
    private final PostgraduateExperienceDAO postgraduateDAO = JDBIDaoFactory.getPostgraduateExperienceDAO();
    private final PostgradCourseDAO pgCourseDAO = JDBIDaoFactory.getPostgradCourseDAO();
    private final UndergradCourseDAO ugCourseDAO = JDBIDaoFactory.getUndergradCourseDAO();

    public Main() {
        setServerOptions(new ServerOptions().setPort(8072));

        install(new GsonModule());
        install(new OpenAPIModule());

        assets("/openapi.json", "mentor-matcher.json");
        assets("/openapi.yaml", "mentor-matcher.yaml");
        assets("/*", Paths.get("app/static"));
        //get("/", ctx -> ctx.sendRedirect("/swagger"));
        
        mount(new PersonModule(personDAO));
        mount(new MentorModule(mentorDAO));
        mount(new MenteeModule(menteeDAO));
        mount(new MatchModule(matchDAO));
        mount(new UndergraduateExperienceModule(undergraduateDAO));
        mount(new PostgraduateExperienceModule(postgraduateDAO));
        mount(new PostgradCourseModule(pgCourseDAO));
        mount(new UndergradCourseModule(ugCourseDAO));

    }

Any and all help will be appreciated:) Thank you

The error was the line setServerOptions(new ServerOptions().setPort(8072)); in my main class.

Once i removed that it started working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM