所以我使用Gradle构建了一个spring boot应用程序。 它在本地构建和运行时工作正常,但是,我无法在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
我有这个Procfile:
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的情况下运行它,但它仍然无法正常工作。
答案 0 :(得分:0)
您应该在Procfile中指定带有版本的jar名称,如下所示。
web: java -jar build/libs/bristech-1.0-SNAPSHOT.jar
答案 1 :(得分:0)
显然,问题出在我的gradle.build文件中。
我正在使用implementation
添加新的依赖项而不是compile
。
我一改变它就像一个魅力......
我认为implementation
是编译的新版本,它将取代它..