无法在heroku中运行基于gradle的webapp

时间:2017-04-10 19:25:15

标签: heroku gradle web-deployment heroku-toolbelt procfile

以下是我的尝试。

以下是我的 build.gradle

/*
 * This build file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * user guide available at https://docs.gradle.org/3.4/userguide/java_library_plugin.html
 */
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '1.0'

repositories {
    mavenLocal()
    mavenCentral()
}

sourceSets {
    main {
        resources.srcDirs = ["src"]
        java {
            srcDir 'src'
        }
    }
}

task stage {
    dependsOn build
}
stage.mustRunAfter(clean)

dependencies {
    compile fileTree(dir: './webapp/WEB-INF/lib', include: ['*.jar'])

    compile 'org.springframework:spring-webmvc:4.2.5.RELEASE'

    compile 'org.apache.poi:poi:3.14'
    compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.5'
    compile 'org.slf4j:slf4j-api:1.7.21'
    compile 'org.apache.logging.log4j:log4j-api:2.5'
    compile 'org.apache.logging.log4j:log4j-core:2.5'

    compile group: 'javax.validation', name: 'validation-api', version: '1.1.0.Final'
    compile group: 'org.json', name: 'json', version: '20141113'

    compile group: 'mysql', name:'mysql-connector-java', version:'5.1.36'
    compile group:  'org.mybatis',name:'mybatis-spring',version:'1.2.3'
    compile group:  'org.mybatis',name:'mybatis',version:'3.3.0'

    compile group: 'org.springframework', name:'spring-orm', version:'3.1.2.RELEASE'
    compile group: 'org.springframework', name:'spring-jdbc', version:'3.1.2.RELEASE'
    compile group: 'org.springframework', name:'spring-webmvc', version:'3.1.2.RELEASE'
    compile group: 'commons-dbcp', name:'commons-dbcp', version:'1.2.2'
    compile group: 'org.activiti', name: 'activiti-engine', version: '5.18.0'

    compile group: 'javax.mail', name:'mail', version:'1.4.3'

    compile group: 'commons-fileupload', name:'commons-fileupload', version:'1.3.2'
    compile group: 'commons-io', name:'commons-io', version:'1.3.2'
    compile group: 'org.apache.axis', name:'axis', version:'1.4'
    compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
    compile group: 'commons-logging', name: 'commons-logging', version: '1.1.3'
    compile group: 'javax.xml', name: 'jaxrpc-api', version: '1.1'
    compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
    compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
    compile group: 'org.twitter4j', name: 'twitter4j', version: '4.0.4'
    compile group: 'org.twitter4j', name: 'twitter4j-stream', version: '3.0.5'

    providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
    testCompile 'junit:junit:3.8.1'
}

Procfile

web: build/install/twitter-api9/bin/TwitterApi

当我从邮递员那里给我的api打电话时,我得到了以下错误。

错误日志:

2017-04-10T19:11:21.820853+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-10T19:11:26.250394+00:00 heroku[web.1]: Starting process with command `build/install/twitter-api9/bin/TwitterApi`
2017-04-10T19:11:28.283776+00:00 heroku[web.1]: Process exited with status 127
2017-04-10T19:11:28.198888+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2017-04-10T19:11:28.199032+00:00 app[web.1]: bash: build/install/twitter-api9/bin/TwitterApi: No such file or directory
2017-04-10T19:11:28.324886+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-10T19:11:50.592336+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/main/twitter_data" host=twitter-api9.herokuapp.com request_id=69ce91fa-9677-4b51-9190-dc40bf0f1648 fwd="49.205.228.96" dyno= connect= service= status=503 bytes= protocol=http

我认为procfile中存在错误,因为我的构建成功但唯一的问题就是当我尝试访问我的应用程序/ api时。该应用程序是spring mvc application,在本地tomcat中部署了war,运行良好。

编辑:

Procfile 更改为我的战争所在的位置

web: sh build/libs

现在错误是:

虽然进程以状态0退出,我猜这意味着一切都很好。但仍然应用程序崩溃:

2017-04-11T14:37:32.333327+00:00 heroku[web.1]: State changed from crashed to starting
2017-04-11T14:37:37.394992+00:00 heroku[web.1]: Starting process with command sh build/libs
2017-04-11T14:37:39.356372+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2017-04-11T14:37:39.441553+00:00 heroku[web.1]: Process exited with status 0
2017-04-11T14:37:39.458917+00:00 heroku[web.1]: State changed from starting to crashed
2017-04-11T15:17:01.974207+00:00 heroku[run.7895]: Awaiting client
2017-04-11T15:17:02.034572+00:00 heroku[run.7895]: Starting process with command bash
2017-04-11T15:17:02.290336+00:00 heroku[run.7895]: State changed from starting to up
2017-04-11T14:38:47.445653+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/main/twitter_data" host=twitter-api9.herokuapp.com request_id=1673e258-3fc2-4630-ac22-4869b8e68b13 fwd="49.205.228.96" dyno= connect= service= status=503 bytes= protocol=https

1 个答案:

答案 0 :(得分:0)

  

逐步说明如何解决此问题:

  1. 首先检查.war文件的部署位置,可以按如下方式进行:

    从cli。

  2. 运行$ heroku run bash -a twitter-api9
  3. 现在终端已打开,请检查当前目录的ls。我相信如果不仅仅是grep for .war文件,build将是其中之一。

  4. 一旦你知道了战争地点,你的 Procfile 就会改为下面(对我而言,战争存在于build / libs /中可能与其他人不同):

  5. <强> web: java $JAVA_OPTS -DTG_ENV=prod -jar webapp-runner.jar --port $PORT build/libs/*.war

    以上内容会将请求重定向到这些位置,因为这是一个Web应用程序,您需要 webapp-runner.jar /或jetty-runner或等效才能运行战争如果它是一个罐子需要。

    1. 现在应用程序正在运行并准备接收请求。但请注意,如果构建成功并且webapp-runner.jar位于root目录中,则上述方法有效,否则请提及jar的完整路径。