0

I'm trying to deploy a Spring Boot REST API to Heroku.

It successfully uploads the files to Heroku's Git repository.

But it is not creating the database tables and so the app doesn't work.

This is how I'm doing on the CLI.

git add .
git commit -m "message"
heroku login
heroku create myappname
heroku addons:create heroku-postgresql:hobby-dev
git push heroku main

Tried with several different application.properties (as below) and none of them was successful. (user/passwords below are fake. Just for explanation purpose)

application.properties test1

spring.jpa.hibernate.ddl-auto=create

application.properties test2

spring.datasource.url=${JDBC_DATABASE_URL}
spring.datasource.username=${JDBC_DATABASE_USERNAME}
spring.datasource.password=${JDBC_DATABASE_PASSWORD}
spring.jpa.hibernate.ddl-auto=create

application.properties test3

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=postgres://aooswjxdniusmd:f99447ede191d139d32f1e3d539dc8ty4535c65350a51960d887km44d6we7c4@ec2-21-567-987-345.compute-1.amazonaws.com:5432/q5kl3s76jh08yt

application.properties test4

spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=postgres://aooswjxdniusmd:f99447ede191d139d32f1e3d539dc8ty4535c65350a51960d887km44d6we7c4@ec2-21-567-987-345.compute-1.amazonaws.com:5432/q5kl3s76jh08yt

application.properties test5

spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.type=info

application.properties test6

spring.datasource.url=${JDBC_DATABASE_URL}
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true

application.properties test7

spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=false
spring.jpa.properties.hibernate.type=info

UPDATE:

I ran heroku logs --tail to take a look at the logs.

Two entries called my attention:

heroku[router]: at=error code=H14 desc="No web processes running"

Error: Unable to access jarfile target/myapp-0.0.1-SNAPSHOT.jar

Then I tried the following:

java -jar myapp-0.0.1-SNAPSHOT.jar

Also got the same error message:

Error: Unable to access jarfile myapp-0.0.1-SNAPSHOT.jar

So that seems to be the cause of the issue.

Not sure why it is happening though.

jkfe
  • 549
  • 7
  • 29
  • Hard to say what's going on without looking at the startup logs for Spring Boot. Maybe it cannot connect to your remote SQL cluster? – A M Feb 22 '21 at 22:34
  • @A M I added to the question some error messages I got from the log. Not sure why that's happening. – jkfe Feb 22 '21 at 22:52
  • Well it seems that the JAR file cannot be found possibly because it is generated with a different name when `mvn package` is called. Maybe try calling JAR by using `java -jar target/*.jar` instead of the specific name. By default, Maven would generate the JAR inside target folder. – A M Feb 22 '21 at 22:59
  • @A M Now I ran the following: ```java -jar target/myapp-0.0.1-SNAPSHOT.jar``` It did find the jar file and executed it. Some other error showed up, but not the "Unable to access jarfile" which is the one that is being generated in heroku. The only difference is that now I added the folder target to the command. And on heroku error logs it does show the target folder: ```Error: Unable to access jarfile target/myapp-0.0.1-SNAPSHOT.jar``` So now question becomes why heroku is not finding the file. – jkfe Feb 22 '21 at 23:13
  • If you are running that command locally, it might work because the JAR has been generated in the target folder if you check that. I do not know what your Procfile looks like or if it is autogenerated but you can check out this answer and see if it helps: https://stackoverflow.com/a/60215244/2081730 – A M Feb 22 '21 at 23:19
  • @A M I tried some of the configurations from the link you provided. With procfile I kept getting ```Error: Unable to access jarfile target/myapp-0.0.1-SNAPSHOT.jar```. Then I removed procfile and also removed `````` from pom.xml like suggested in the link. That did remove the old ```No web processes running``` message. But still doesn't run the app. The error now is ```State changed from crashed to down``` Procfile I tried had the following content: ```web: java -Dserver.port=$PORT -Dspring.profiles.active=default -jar target/myapp-0.0.1-SNAPSHOT.jar``` – jkfe Feb 23 '21 at 01:13
  • @A M Noted another thing. When I do a git clone, it downloads the code from heroku but it doesn't download the .jar file. So wondering if the jar file is really being pushed to heroku and if that should happen at all. – jkfe Feb 23 '21 at 11:25
  • your problem could be that you are pushing your code to a branch named "main" and Heroku by default works with master so in your case, it wouldn't find anything to deploy on master. So maybe try pushing to master? You could also look here in the Maven plugin section : https://stackabuse.com/deploying-spring-boot-applications-to-heroku/ – A M Feb 23 '21 at 12:13
  • @A M I got it to work! Just removed the app from heroku and created a new one with the same name. Now everything that was not working, now works. So I think the first one was corrupted in some way. One thing that also leads me to believe that, is that when the app was accessed on the url it would show a "Application error". Now, even before deploying the code and creating the db it shows a "Heroku | Welcome to your new app!". Deploying to main is not the problem. Heroku supports that. In fact it is migrating from master to main just like github.https://devcenter.heroku.com/changelog-items/1829 – jkfe Feb 23 '21 at 15:03

0 Answers0