Java – spring boot gradle application on heroku: unable to access jarfile
•
Java
I have a spring boot gradle app that I can run successfully on my computer:
heroku local
When I go, it can also be successfully deployed on heroku:
git push heroku master
This is my result:
Counting objects: 17,done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5),done. Writing objects: 100% (9/9),596 bytes | 0 bytes/s,done. Total 9 (delta 3),reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Fetching set buildpack https://github.com/heroku/heroku-buildpack-gradle... done remote: -----> Gradle app detected remote: -----> Installing OpenJDK 1.8... done remote: -----> Building Gradle app... remote: WARNING: The Gradle buildpack is currently in Beta. remote: -----> executing ./gradlew build remote: :compileJavaNote: Some input files use unchecked or unsafe operations. remote: Note: Recompile with -Xlint:unchecked for details. remote: remote: :processResources remote: :classes remote: :jar remote: :bootRepackage remote: :assemble remote: :compileTestJava UP-TO-DATE remote: :processTestResources UP-TO-DATE remote: :testClasses UP-TO-DATE remote: :test UP-TO-DATE remote: :check UP-TO-DATE remote: :build remote: remote: BUILD SUCCESSFUL remote: remote: Total time: 11.935 secs remote: remote: -----> Discovering process types remote: procfile declares types -> web remote: remote: -----> Compressing... done,72.3MB remote: -----> Launching... done,v9 remote: https://myapp.herokuapp.com/ deployed to Heroku remote: remote: Verifying deploy... done. To https://git.heroku.com/myapp.git 6326429..291326d master -> master
But when I try to access it on heroku, it crashes The heroku log says:
2015-12-11T17:05:46.096985+00:00 heroku[api]: Deploy 291326d by xxx@gmail.com 2015-12-11T17:05:46.097021+00:00 heroku[api]: Release v9 created by xxx@gmail.com 2015-12-11T17:05:46.378258+00:00 heroku[slug-compiler]: Slug compilation started 2015-12-11T17:05:46.378269+00:00 heroku[slug-compiler]: Slug compilation finished 2015-12-11T17:05:46.755655+00:00 heroku[web.1]: State changed from crashed to starting 2015-12-11T17:05:53.121398+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=5000 -jar build/libs/myapp.jar` 2015-12-11T17:05:54.260741+00:00 app[web.1]: Error: Unable to access jarfile build/libs/myapp.jar 2015-12-11T17:05:54.784064+00:00 heroku[web.1]: State changed from starting to crashed 2015-12-11T17:05:54.773714+00:00 heroku[web.1]: Process exited with status 1 2015-12-11T17:05:54.788248+00:00 heroku[web.1]: State changed from crashed to starting
Why can't I access jarfile build / LIBS / myapp jar?
When I navigate to this folder on my local PC, the jar file is there
I don't have many ideas about how to solve this problem
Solution
I finally found a very useful post here: running spring app build with gradle on heroku
This helped me solve my problem - this post seems to be more detailed than heroku's official guide
You must add the following code to build In the gradle file:
task stage(type: Copy,dependsOn: [clean,build]) { from jar.archivePath into project.rootDir rename { 'app.jar' } } stage.mustRunAfter(clean) clean << { project.file('app.jar').delete() }
Then, point your procfile to app jar:
web: java $JAVA_OPTS -jar app.jar
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码