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.
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.
Related
I recently run into an "H14 Error" While Trying To Deploy Gradle Spring Project into the HeroKu platform.
Error:
code=H14 desc="No web processes running"
In My Project Folder, I have a "Procfile"
web: java -jar build/server/webapp-runner-*.jar build/libs/*.war
web: java -jar target/ClockGUI-0.0.1-SNAPSHOT.jar
heroku ps:scale web=1
I have researched many solutions but not worked out.
Please help me. Thank you so much
There are at least two issues with your Procfile:
You can't declare two web processes.
What command runs your web server? That's the only one that should be declared this way.
(I'm not sure what ClockGUI-0.0.1-SNAPSHOT.jar is supposed to be, but assuming "GUI" means something like SWT, Swing, or JavaFX, it won't work on Heroku. Where would the interface appear?)
You've included a Heroku CLI command.
heroku ps:scale web=1 is a command that you might run locally to scale your application's web dynos. It's not something that should be baked into the application source code.
Consider an e-commerce application. At certain times of the year, you might see a spike in traffic. You could use this command to scale up additional web dynos to handle the load. That doesn't (and shouldn't) require redeploying the application.
Remove that line. It doesn't do anything in the Procfile anyway.
Commit the updated Procfile and redeploy. Then, if you don't have any web dynos running, run heroku ps:scale web=1 in a terminal, ideally from your project directory so Heroku can infer which app you want to scale.
I'm looking for a way to run Heroku CLI commands within a java application hosted on Heroku.
I'd like to be able to run commands like heroku pg:backup heroku pg:restore etc
Is there a way to do that ?
EDIT : I added the Heroku CLI to my app, now I'm looking for a way to invoke heroku commands from my java code.
Maybe you could use something like this :
ProcessBuilder pb = new ProcessBuilder("/path/to/herokuCLI", "myCommand");
Problem is I don't know how to find the right path.
If you look at the file structure of your app on Heroku you can only find your .war + some "configuration files" which is quite normal as you only push a war to Heroku : Procfile system.properties target
Besides I don't think that's the right way to do that.
I'd like to avoid doing backup/restore operations in pure java code.
Maybe you can't rely on Heroku cmd to do the job for you after all.
You'll need to add the Heroku CLI buildpack to your application. You can do so with: heroku buildpacks:add heroku-community/cli
Push a new build after you've done so and you'll now be able to run CLI commands from inside your application dynos. You can see some additional information about this in the documentation.
I created a simple Java (maven) web application (WAR). On local Tomcat all works fine, however when I try to deploy to HEROKU the application does not show up (I get error instead on the home page of the app.
I run this command
heroku war:deploy myapp-ws-0.0.1-SNAPSHOT.war --app myapp-ws
and all actions are successful
the only parameter that I need on Heroku for my app to run is spring profile and I added it this way.
heroku config:set -Dspring.profiles.active="true"
I'm very new to heroku, but did anyone in the past deploy a war to heroku successfuly? I cannot find the problem, no error appears apart from the home page saying application Application Error. Any other information I should include here?
Ok, I got it working, first I was able to check logs:
heroku logs --tail --app myapp-ws
then I found out that you have to add one instance because at start there are zero
heroku ps:scale web=1
and finally I added my arguments in this way
heroku config:set WEBAPP_RUNNER_OPTS="-Dspring.profiles.active=test" --app myapp-ws
I try to deploy java on Heroku. I follow the steps on Heroku
,But I get error on
java -cp target\classes;"target\dependency\*" HelloWorld
the error is :
Error: Could not find or load main class HelloWorld
How can I solve it? Is it case sensitive?
I found helloworld key word in pom.xml, so I try to change it to HelloWorld. It still does not work. btw, I am running windows 7(64 bit) with jdk1.7.0_05.
Looks like you are using Windows-style path for the -cp flag. Heroku runs on Linux, so you probably need to change that to java -cp target/classes:"target/dependency/*" HelloWorld in the Procfile you are deploying to Heroku.
For any avid readers who are trying to follow Heroku's getting started tutorial and are attempting to deploy locally and are receiving this error...
It is likely that you haven't built the target classes locally (they don't explain it very well in the tutorial).
If you are following the getting started guide with Maven then execute the following maven command in your project root folder to build your target locally:
mvn clean install
After that the local deployment commands like:
heroku local web -f Procfile.windows
should work as expected. (Obviously substitute Procfile.windows with just Procfile if you are not deploying under Windows)
You should then see something like:
Started ServerConnector#4d29c891{HTTP/1.1}{0.0.0.0:5000}
and can access your application locally by navigating to localhost on the port that was displayed:
localhost:5000
When I'm trying to run my Play! application on Herocu I have a message that I should run it with "play -DapplyEvolutions.default=true" command. But how can I do it?
Now what I'm doing is pushing to my webapp to heroku and operate with commands: "heroku ps" and "heroku logs". The last one gives me error details. How can I run application on heroku remotely?
Is this Play 2? If so you will need a Procfile containing:
web: target/start -Dhttp.port=$PORT -DapplyEvolutions.default=true -Ddb.default.driver=org.postgresql.Driver -Ddb.default.url=$DATABASE_URL