Setup jar to run as service on Ubuntu

zolf
zolf used Ask the Experts™
on
Hello there,

Now I have a jar application on my Ubuntu server and is located in /home/steve/deployment/bear.server-1.0-SNAPSHOT-fat.jar and everytime i want to run my application I need to run this cmd
 java -jar bear.server-1.0-SNAPSHOT-fat.jar -conf config.json

Open in new window

. I want to know how I can run this cmd with a shotcut for e.g. run myapp. Please help!!

cheers
Zolf
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
What does bear.server-1.0-SNAPSHOT-fat.jar do? Tanukisoft probably still make their service wrapper. Whether it's been updated to cope with systemd is another issue. If it hasn't, you can write your own systemd service
David FavorFractional CTO
Distinguished Expert 2018
Commented:
Be sure you make all your files absolute paths, or likely you'll have no end of troubles. This includes both your .jar + .conf file.

In your system wide or user shell startup file, you can add...

alias mycmd=" java -jar bear.server-1.0-SNAPSHOT-fat.jar -conf config.json"

Open in new window


Or you can take CEHJ's suggestion + turn the above into a systemd service, so then you'd use something like...

service mycmd start

Open in new window


Where your mycmd service implemented parts of service management you require.

Author

Commented:
Thanks for all your comments.

David

In your system wide or user shell startup file, you can add...
Can you please elaborate more, I am new to ubuntu world.

CEHJ
What does bear.server-1.0-SNAPSHOT-fat.jar do?
It runs my server side application.

If it hasn't, you can write your own systemd service
Can you please tell me how to setup with reference to my jar file location which is in my home directory
Top Expert 2016
Commented:
Can you please tell me how to setup with reference to my jar file location which is in my home directory
The answer to that is - not easily. It would depend on the context. If you'd like to try it the 'proper' (but initially harder) way, then you need to study something like https://wiki.archlinux.org/index.php/Systemd

I would imagine the Tanukisoft wrapper would be easier. If it's well maintained, it will do the above for you
I'm also imagining that the service is network-oriented - is that the case?

Author

Commented:
cheers

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial