I have a java tool that I use quite often from the command line but to use it I have to type java -jar dsim.jar
. I want to make it so that I can call it just by typing dsim
regardless of what directory I am in, but I can't quite work out how to accomplish this.
I have created a file at ~/.bash_profile
and put into it:
alias dsim='java -jar dsim.jar'
And I have placed the dsim.jar file into /usr/local/bin
as I read this is where user created command line tools should be kept. This location is in my $PATH.
I think the alias works well but location of the file doesn't seem to be accessible from anywhere. If I call dsim
from within /usr/local/bin
it works fine but if I am in any other directory I get:
Error: Unable to access jar file dsim.jar
How can I get this to work from any directory?
Best Answer
Use absolute paths for the jar file: