Heroku run Jar file once deployed? - heroku

I have deployed my jar file to heroku using:
heroku deploy:jar <filename>.jar --app <appname>
Once deployed, how do I run the jar file with specific params, i.e. locally i would execute:
java -jar <filename>.jar <param1> <param2>
Am i using the Heroku service correctly? In essence I just need to run the Main command within the jar file and get the logs when completed.
Any help would be much appreciated.

heroku deploy:jar <filename>.jar --app <appname>
With this you essentially hardcorded:
jar <filename>.jar
Here is an example where you can configure parameters for your command
https://github.com/NNTin/shell-kun/tree/6b35e4b731bcf500366f60bbceafe076bf969fe1
Note: We are looking here at older software because HEAD no longer has it.
You need Procfile. app.json and the Heroku Deploy (see link in README.md) button are optional. They make deploying easier since you don't have to touch terminal/CLI.
Essentially you extend your Procfile to:
web: jar <filename>.jar $ARGS_AND_FLAGS
worker: jar <filename>.jar $ARGS_AND_FLAGS
web when you are utilizing a $PORT, worker when not.
Now you can modify your command by editing the environment variable ARGS_AND_FLAGS.
In this case the web process is activated and the worker process is deactivated.
After you changed your environment variable you can deactivate and then activate your process.

Create a Procfile in the same directory where you run heroku deploy:jar with the content:
web: java -jar <filename>.jar <param1> <param2>
and redeploy the app.

Related

How does Heroku knows which file use to deploy?

I always create a file called server.js as entry point of my Node.js app and I always deploy to Heroku with that file but... How does Heroku know that server.js the file that it should to execute?
What if my server file is called anotherName.js? How can I tell to Heroku to deploy anotherName.js?
If you have a Procfile, Heroku will look there first.
If no Procfile exists, Heroku will try to run the start sript defined in your package.json.
What if my server file is called anotherName.js? How can I tell to Heroku to deploy anotherName.js?
Either by modifying (or creating) your Procfile or by changing the start script in your package.json.

Heroku Discord Bot builds but doesn't work

I am trying to host a discord bot on Heroku (Discord JDA, Maven). I do this by connecting to Github and then deploying. The bot 'deploys' (view attachment) but doesn't actually work (view attachment).
What could I be doing wrong, or has anyone else come across a similar issue?
Quick and dirty way to deploy it:
You'll need to setup a Procfile, extensive info on that right here: https://devcenter.heroku.com/articles/procfile
The procfile is basically a file with no extension that tells the dyno how to execute your program.
A simple
worker: java $JAVA_OPTS -jar <PATH_TO_JAR>
will work fine if you don't need more config, refer to that link for more.
You can then deploy it like this (Good to have procfile and jar on the same directory):
$ heroku deploy:jar -a <YOUR_HEROKU_APP_NAME> --jdk <JDK_VERSION> --jar <PATH_TO_JAR> -i Procfile
Then to start it just do (Assuming you want a worker dyno, which is what discord should need)
$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=1
Then stop it with:
$ heroku ps:scale -a <YOUR_HEROKU_APP_NAME> worker=0
I've found this is much simpler than using git, especially if you're doing tests or simple/quick stuff.
Possible solutions:
Set up a Procfile. A Procfile basically tells Heroku what command to run when your app is deployed. Inside the Procfile, write worker: node index.js. Also, make sure Procfile has a capital "P".
Set up package.json.
npm init
Then just skip through the set up and your file should be automatically created. IMPORTANT. In your package.json file, add your node and npm versions.
node -v
npm -v
Then go an type this in your package.json.
"engines": {
node: "your-version-here"
npm: "your-version-here"
}
Then try deploying your app to Heroku again. Also, make sure you have the "nodejs" buildpack set up for your app. Run it and test the discord bot.

How can I deploy to a specific app with heroku docker:release?

Using the heroku docker:release command, how can I specify which app to release to? I can't see from any documentation whether there's any switch for this purpose.
Heroku commands take their context from the directory you are in when you run them.
Go into the directory from where you did heroku create then run heroku docker:release.
If you haven't used heroku create, then you can specify the app name with the --app <APP NAME> command line parameter. for instance, if you were to release to the app named f00 you would type:
heroku docker:release --app f00

AngularJS - Deploy on Heroku

I created a app for Angular manually, his structure and all stuff.
To run it locally I'm using http-server.
How can I deploy it to Heroku in order to inform what server to run (probably in Procfile)?
Create a Procfile just called Procfile (no extension) in the root of your app. Within that file use web: to tell heroku what to run. For example:
web: coffee server.coffee

HEROKU: ps:scale web=1 no such process type web defined in Procfile

I have seen very similar posts, that however did not help me to find a solution to my problem.
I am following step by step the guide to upload a project on heroku.
However when I type the command:
ps:scale web=1
The result is:
no such process type web defined in Procfile
I have created a file "Procfile" being careful at the capitalization. but nothing.
What else can I do to solve this problem??
Thanks in advance.
Follow on this heroku procfile
:
We have to define web process type in your Procfile and make sure name Procfile exactly, and not anything else. For example, Procfile.txt is not valid.
Example:
a: Python:
web: gunicorn gettingstarted.wsgi --log-file -
b: String MVC Hibernate
web: java $JAVA_OPTS -jar target/dependency/jetty-runner.jar --port $PORT target/*.war
This declares a single process type, web, and the command needed to run it. The name web is important here. It declares that this process type will be attached to the HTTP routing stack of Heroku, and receive web traffic when deployed.
Procfiles can contain additional process types.
worker: bundle exec rake jobs:work
Hopefully you've fixed your problem after all this time, but just in case you haven't...
I've run into this problem when my Procfile doesn't exist (a web app that I'm porting to Heroku) or doesn't match the dyno type that I'm trying to deploy (see Heroku No such process type web defined in procfile for an example of that).
You've created your Procfile, but what did you put in there? For a website Node.js app, you'll need to put in:
web: node app.js
(Obviously you'll replace app.js with index.js or wherever your app starts)
For more about Procfiles (or for other languages than Node.js), see https://devcenter.heroku.com/articles/procfile

Resources