I have a jar file located at /home/ec2-user/Back-end
and I want to make it runnable from everywhere, like a normal command.
So, I created a bash file myprogram
in /usr/bin
and I entered my command java -jar myprogram.jar $*
I can successfully access my program using the myprogram
command from everywhere. The only problem is that it throws me a FileNotFoundException
, because I need to read/write csv files in this program.
It only happens when I'm not in the folder where the jar file is located. So I imagine that it try to read the csv file from the current folder and not from the jar folder, that's my problem. This is how I want to read my csv file, located in the csv
folder which is in the same folder than my jar file : new FileReader("csv/"+this.name+".csv")
I tried the functions sequences from here How to get the path of a running JAR file? and it works in Eclipse but not from the terminal when running the jar (it returns null).
Any way to make the file relative to the jar location and not to my location ? Otherwise I will just set an absolute path, but I think that it's not the best solution.