简体   繁体   中英

How to deploy java gradle application on Heroku

Please help to deploy my application on Heroku. Getting error message from Heroku *

"Application Error. An error occurred in the application and your page could not be served. Please try again in a few moments. If you are the application owner, check your logs for details."

Here log from Heroku:

2016-07-21T22:11:30.966800+00:00 heroku[slug-compiler]: Slug compilation 
started 2016-07-21T22:11:30.773385+00:00 heroku[api]: Release v8 created by 
zzheads@gmail.com 2016-07-21T22:11:56.184847+00:00 heroku[router]: at=error 
code=H14 desc="No web processes running" method=GET path="/favicon.ico" 
host=zzheads-countries.herokuapp.com request_id=a03c9276-b038-4f9f-8e6d-
5f29f14b441 fwd="5.3.141.153" dyno= connect= service= status=503 bytes=

My gradle build file:

group 'com.zzheads'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath  'org.springframework.boot:spring-boot-gradle-plugin:1.3.6.RELEASE'
    }
}

apply plugin: 'java'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-thymeleaf")
}

task stage {
    dependsOn build
}

And my Proc file:

web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/countries-1.0-SNAPSHOT.jar

Your build probably generates an executable JAR file in the directory build/libs . Try this in your Procfile :

web: java -Dserver.port=$PORT $JAVA_OPTS -jar build/libs/countries-1.0-SNAPSHOT.jar

You can test it locally by running:

$ ./gradlew stage
$ heroku local

I think that Heroku is not able to find your .jar because when it does not find a version property, the gradle buildpack just uses its own build id. So your .jar is not found under the filename in your procfile. You can set the following:

jar{
  baseName = 'countries-'
  version = '1.0-SNAPSHOT'
} 

so Heroku picks up on those variables. Note that if you're using Spring Boot 2.*, the plugin disables the jar tasks, and adds a bootJar task on which you then have to set these to variables.

With that, the platform should be able to find your artifact just fine.

Also, running heroku logs -a <your-app-name-here> -t you'll get some more information about the status of your app while debugging

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