1

I have a Java web app with Tomcat embedded in my jar file. I can containerize the app with Docker and run it with command java -jar -myapp.jar, but I can't run that container in Heroku. I tried using heroku CLI to dockerize and deploy, but Heroku gives me an error of "can't access jarfile".

I tried to fix this by using heroku deploy:jar to deploy my fat jar, but this erroneously gives me an error:

 heroku deploy:jar target/*.jar -a medscanner2
-----> Packaging application...
   - app: medscanner2
   - including: target/medscanner2.jar
   ! ERROR: Could not get API key! Please install the Heroku CLI and run 
   `heroku login` or set the HEROKU_API_KEY environment variable.
   ! Re-run with HEROKU_DEBUG=1 for more info.
   !There was a problem deploying to medscanner2.
   !Make sure you have permission to deploy by running: heroku apps:info -a 
    medscanner2

I am signed into Heroku and I can use heroku auth:whoami to verify that, I can push containers and deploy them, so this error doesn't make any sense. I reran with HEROKU_DEBUG=1 and it did not return any more info.

I further tried to set the HEROKU_API_KEY variable in the CLI with a token I got from Heroku and this still caused the same error when I try to deploy the jar.

I am using a Procfile (although I am not sure it is necessary):

web: java -Dserver.port=$PORT -jar target/medscanner2.jar

Since the issue seems to be indicating there is an issue with access I don't see how the Procfile could be influencing it.

What is the best way for me to deploy a Java web app that does not using Spring Boot to Heroku? I have separately deployed the docker container successfully to Google app engine, so all this work for Heroku is very frustrating.

1 Answer 1

2

I ended up fixing this by using webapp-runner to deploy my app. It runs the webapp-runner jar which can run your .war files. This required adding the heroku-maven-plugin and maven-dependency-plugin.

I could then add a Procfile: web: java -jar target/dependency/webapp-runner.jar target/*.war --port $PORT

and use the Heroku CLI to add the app using git. The link with webapp-runner is a guide to deploying tomcat java apps with webapp-runner.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.