我 正在 尝试 使用 Gradle 部署 Java 应用 程序 , 并且 能够 执行 所有 部署 步骤 , 但是 当 我 在 部署 后 编写 heroku open
时 , 屏幕 会 保持 白色 一 段 时间 , 然后 日志 返回 错误
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
中 的 每 一 个
我 的 proc 文件 配置 为
web: java $JAVA_OPTS -Dserver.port=$PORT -jar app/build/libs/app-all.jar
格式
我 的 身材 。
/*
* 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 = []
}
}
}
格式
最 后 是 我 的 主 类
/*
* 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));
}
格式
任何 和 所有 的 帮助 将 不胜 感激 : ) 谢谢 你
1条答案
按热度按时间0ve6wy6x1#
错误是我的主类中的
setServerOptions(new ServerOptions().setPort(8072));
行。一旦我把它取下来,它就开始工作了。