I have created a test.jar file that will execute "pwd" command and will write it to pathFile. I am able to run the test.jar by double clicking on it. location of test.jar is "/home/akashm/Desktop/IDE/test/test.jar".Now I have following problems-
1. If I run test.jar from terminal i.e.
$java -jar test.jar
I get "/home/akashm/Desktop/IDE/test/" as output. This is correct.
2. If I run test.jar by double clicking it then I get
"/home/akashm" as output.
Does anyone has any idea of ambiguity in execution of test.jar file?
akki maha wrote:I got the solution for this problem just now,
This will give the exact location of the file from where it is getting executed.
Thanks for posting the solution akki! =)
You can use s.getPath() instead of s.toString()
I made a little hack to remove the name of the jar:
And it works like a charm!
But I'm frustrated about this problem. Why when we execute the jar file by clicking on it, it doesn't get the path where the jar file is located? Why does It only show /home/<user-name>?
Someone help us!! Please.
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
a bit of art, as a gift, that will fit in a stocking