cHam
cHam

Reputation: 2664

Can I make a jar file runnable from any directory?

I am curious if I can take a .jar file and somehow add it to my classpath so that I can run it from any directory. For example, let's say I have a .jar located at /home/setup/someJar.jar. Is there a way I can run this from another directory (preferably any) so that I do not have to navigate back to /home/setup/ whenever I want to run it?

I tried adding the path to my .bash_profile file by adding :/home/setup to the PATH= line, but didn't work.

Upvotes: 2

Views: 508

Answers (3)

Festus Tamakloe
Festus Tamakloe

Reputation: 11310

It's possible but not so easy. you have 3 possiblities

  1. Make an alias or symbolic link (create symbolic link)

  2. Start it as deamon

  3. start it as service (create service)

after ready the information above

you can start it like this

service [yourservice] start|stop|restart

Upvotes: 2

MobA11y
MobA11y

Reputation: 18860

I think you probably want an 'alias'.

http://www.linfo.org/alias.html

alias myJarShortcut="java -jar /direct/path/to/nameOfYourJar.jar"

Add this to your .bash_profile and it will be available every time you boot up.

Upvotes: 3

lightalex
lightalex

Reputation: 879

You could create a bash script that execute your .jar file in the directory of your choice, with of course the right path to your .jar file.

Upvotes: 1

Related Questions