Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 在Heroku上未运行Spring boot_Spring Boot_Heroku - Fatal编程技术网

Spring boot 在Heroku上未运行Spring boot

Spring boot 在Heroku上未运行Spring boot,spring-boot,heroku,Spring Boot,Heroku,因此,我用Gradle构建了一个spring引导应用程序。 在本地构建和运行时,它工作得很好,但是,我不能让它在Heroku上运行。以下是日志: 2018-03-10T22:24:19.561282+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=53342 $JAVA_OPTS -jar build/libs/*.jar` 2018-03-10T22:24:21.446741+00:00 app[we

因此,我用Gradle构建了一个spring引导应用程序。 在本地构建和运行时,它工作得很好,但是,我不能让它在Heroku上运行。以下是日志:

2018-03-10T22:24:19.561282+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=53342 $JAVA_OPTS -jar build/libs/*.jar`
2018-03-10T22:24:21.446741+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2018-03-10T22:24:21.458097+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-03-10T22:24:21.461370+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8
2018-03-10T22:24:21.701767+00:00 app[web.1]: Exception in thread "main" java.lang.reflect.InvocationTargetException
2018-03-10T22:24:21.701779+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-03-10T22:24:21.701781+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2018-03-10T22:24:21.701783+00:00 app[web.1]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-03-10T22:24:21.701784+00:00 app[web.1]:    at java.lang.reflect.Method.invoke(Method.java:498)
2018-03-10T22:24:21.701786+00:00 app[web.1]:    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
2018-03-10T22:24:21.701788+00:00 app[web.1]:    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
2018-03-10T22:24:21.701789+00:00 app[web.1]:    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
2018-03-10T22:24:21.701792+00:00 app[web.1]: Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
2018-03-10T22:24:21.701791+00:00 app[web.1]:    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
2018-03-10T22:24:21.701794+00:00 app[web.1]:    at com.bristech.BristechApp.main(BristechApp.java:12)
2018-03-10T22:24:21.701795+00:00 app[web.1]:    ... 8 more
2018-03-10T22:24:21.701797+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
2018-03-10T22:24:21.701798+00:00 app[web.1]:    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
2018-03-10T22:24:21.701800+00:00 app[web.1]:    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
2018-03-10T22:24:21.701802+00:00 app[web.1]:    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
2018-03-10T22:24:21.701804+00:00 app[web.1]:    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
2018-03-10T22:24:21.701805+00:00 app[web.1]:    ... 9 more
2018-03-10T22:24:21.828827+00:00 heroku[web.1]: Process exited with status 1
2018-03-10T22:24:21.845444+00:00 heroku[web.1]: State changed from starting to crashed
2018-03-10T22:24:21.848108+00:00 heroku[web.1]: State changed from crashed to starting
2018-03-10T22:24:24.295261+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=48859 $JAVA_OPTS -jar build/libs/*.jar`
2018-03-10T22:24:25.862214+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-03-10T22:24:25.849109+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2018-03-10T22:24:25.865381+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -Dfile.encoding=UTF-8
2018-03-10T22:24:26.065973+00:00 app[web.1]: Exception in thread "main" java.lang.reflect.InvocationTargetException
2018-03-10T22:24:26.066210+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-03-10T22:24:26.066306+00:00 app[web.1]:    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2018-03-10T22:24:26.066354+00:00 app[web.1]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-03-10T22:24:26.066402+00:00 app[web.1]:    at java.lang.reflect.Method.invoke(Method.java:498)
2018-03-10T22:24:26.066464+00:00 app[web.1]:    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
2018-03-10T22:24:26.066593+00:00 app[web.1]:    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
2018-03-10T22:24:26.066532+00:00 app[web.1]:    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
2018-03-10T22:24:26.066651+00:00 app[web.1]:    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
2018-03-10T22:24:26.066845+00:00 app[web.1]: Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
2018-03-10T22:24:26.067057+00:00 app[web.1]: Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
2018-03-10T22:24:26.066918+00:00 app[web.1]:    at com.bristech.BristechApp.main(BristechApp.java:12)
2018-03-10T22:24:26.066974+00:00 app[web.1]:    ... 8 more
2018-03-10T22:24:26.067098+00:00 app[web.1]:    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
2018-03-10T22:24:26.067138+00:00 app[web.1]:    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
2018-03-10T22:24:26.067221+00:00 app[web.1]:    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
2018-03-10T22:24:26.067225+00:00 app[web.1]:    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
2018-03-10T22:24:26.067285+00:00 app[web.1]:    ... 9 more
2018-03-10T22:24:26.176301+00:00 heroku[web.1]: Process exited with status 1
2018-03-10T22:24:26.195791+00:00 heroku[web.1]: State changed from starting to crashed
2018-03-10T22:35:56.000000+00:00 app[api]: Build started by user bris47degrees@gmail.com
2018-03-10T22:36:30.552290+00:00 app[api]: Release v4 created by user bris47degrees@gmail.com
2018-03-10T22:36:30.552290+00:00 app[api]: Deploy eb0b8be4 by user bris47degrees@gmail.com
2018-03-10T22:35:56.000000+00:00 app[api]: Build succeeded
2018-03-10T22:36:31.291066+00:00 heroku[web.1]: State changed from crashed to starting
2018-03-10T22:36:34.505370+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/bristech.jar`
2018-03-10T22:36:36.916160+00:00 heroku[web.1]: State changed from starting to crashed
2018-03-10T22:36:36.918820+00:00 heroku[web.1]: State changed from crashed to starting
2018-03-10T22:36:36.899817+00:00 heroku[web.1]: Process exited with status 1
2018-03-10T22:36:36.830058+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-03-10T22:36:36.831354+00:00 app[web.1]: Error: Unable to access jarfile build/libs/bristech.jar
2018-03-10T22:36:39.908150+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/bristech.jar`
2018-03-10T22:36:41.758247+00:00 heroku[web.1]: Process exited with status 1
2018-03-10T22:36:41.698096+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-03-10T22:36:41.700091+00:00 app[web.1]: Error: Unable to access jarfile build/libs/bristech.jar
2018-03-10T22:36:41.771761+00:00 heroku[web.1]: State changed from starting to crashed
2018-03-10T22:40:37.000000+00:00 app[api]: Build started by user bris47degrees@gmail.com
2018-03-10T22:41:11.017941+00:00 app[api]: Deploy a7465293 by user bris47degrees@gmail.com
2018-03-10T22:41:11.017941+00:00 app[api]: Release v5 created by user bris47degrees@gmail.com
2018-03-10T22:40:37.000000+00:00 app[api]: Build succeeded
2018-03-10T22:41:11.805609+00:00 heroku[web.1]: State changed from crashed to starting
2018-03-10T22:41:14.238089+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/bristech_server.jar`
2018-03-10T22:41:15.655343+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-03-10T22:41:15.656220+00:00 app[web.1]: Error: Unable to access jarfile build/libs/bristech_server.jar
2018-03-10T22:41:15.712848+00:00 heroku[web.1]: State changed from starting to crashed
2018-03-10T22:41:15.693130+00:00 heroku[web.1]: Process exited with status 1
2018-03-10T22:42:07.343849+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=bristech-server.herokuapp.com request_id=807880ea-219e-425b-88dc-0265c5800c3b fwd="77.101.215.27" dyno= connect= service= status=503 bytes= protocol=h
ttps
2018-03-10T22:42:07.948730+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bristech-server.herokuapp.com request_id=2928b2e5-6133-454b-ba6a-5809755f0329 fwd="77.101.215.27" dyno= connect= service= status=503 bytes=
 protocol=https
2018-03-10T22:42:11.097608+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/users/1" host=bristech-server.herokuapp.com request_id=d158abb8-e7b3-4dfd-a889-8cf575eec7c0 fwd="77.101.215.27" dyno= connect= service= status=503 bytes= pro
tocol=https
2018-03-10T22:42:11.379526+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=bristech-server.herokuapp.com request_id=8e403565-3112-4a5a-8329-70883b0eb68a fwd="77.101.215.27" dyno= connect= service= status=503 bytes=
 protocol=https
2018-03-10T22:42:27.000000+00:00 app[api]: Build started by user bris47degrees@gmail.com
2018-03-10T22:43:02.996084+00:00 app[api]: Deploy f76796c1 by user bris47degrees@gmail.com
2018-03-10T22:43:02.996084+00:00 app[api]: Release v6 created by user bris47degrees@gmail.com
2018-03-10T22:42:27.000000+00:00 app[api]: Build succeeded
2018-03-10T22:43:03.470870+00:00 heroku[web.1]: State changed from crashed to starting
2018-03-10T22:43:05.898870+00:00 heroku[web.1]: Starting process with command `java -jar build/libs/bristech.jar`
2018-03-10T22:43:07.244601+00:00 heroku[web.1]: Process exited with status 1
2018-03-10T22:43:07.194950+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2018-03-10T22:43:07.195870+00:00 app[web.1]: Error: Unable to access jarfile build/libs/bristech.jar
2018-03-10T22:43:07.258778+00:00 heroku[web.1]: State changed from starting to crashed
我有一个文件:

web: java -jar build/libs/bristech.jar
这是我的gradle.build:

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

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'

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

repositories {
    mavenCentral()
    maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
    maven { url 'https://repo.spring.io/libs-snapshot' }
}

jar {
    baseName = 'bristech'
}

task stage {
    dependsOn build
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
    //Spring web, database and security
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-data-jpa")
    implementation("mysql:mysql-connector-java:5.1.6")
    implementation 'com.google.firebase:firebase-admin:5.9.0'

    //logging
    implementation("org.apache.logging.log4j:log4j-api:2.10.0")
    implementation("org.apache.logging.log4j:log4j-core:2.10.0")

    testCompile group: 'junit', name: 'junit', version: '4.12'
}

我怀疑这个错误与jar文件有关。我也尝试过在没有Procfile的情况下运行它,但是它仍然不起作用。

您应该在Procfile中指定jar名称和版本,如下所示


web:java-jarbuild/libs/bristech-1.0-SNAPSHOT.jar

显然,问题出在我的gradle.build文件中。 我使用
implementation
来添加新的依赖项,而不是
compile
。 我一改,它就很有魅力


我认为
implementation
是compile的新版本,它将取代它

我认为本地运行是指从目标文件夹运行。将jar复制到其他地方并运行,我怀疑这不会起作用,因为jar没有必需的依赖项(因此类未找到异常)。如果你看到了这个问题,试着用spring启动插件创建胖jar。@最好在本地运行,我的意思是我可以用IntelliJ来构建它,但是当我把它推到Heroku时,它构建起来还是不一样的。我不认为这是问题所在,只是不知道该怎么识别这些类。