• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Different reults of execution of jar from terminal and by double clicking

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

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?

Please help me out.


-akash
 
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could you post the code?
 
akki maha
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have created a simple gui, that has password field and "ok" button. Following code is executed when OK button is pressed.

 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure, but add this procout.flush(); before procout.close();
 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
print pwdOut to see what you get
 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same problem with me. If I run the jar through the command line I get the correct result, but clicking on the jar I get /home/leandro



 
akki maha
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the solution for this problem just now,



This will give the exact location of the file from where it is getting executed.


-akki
 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic