-1

I have a runnable jar file that, when run, puts up a gui. The gui can be used to do various things including writing an output file. When I fire up the jar file at the command line by typing java -jar myprogram.jar, it works fine. However, if I start the jar file by double clicking it, the program works fine, but does not write an output file.. At least I don't find the output file where I expect it.

Note 1: The code extracts the current directory (i.e., the directory where the jar file resides). Output files are written to this directory. Note 2: I am working on a Linux machine running Ubuntu.

File currFolder = new File("");
defaultDirectory = currFolder.getAbsolutePath(); 
String outfile = defaultDirectory+"/testfile.mp3"
user3516726
  • 626
  • 6
  • 15
  • This could be a permissions issue - are you running the file in the command line as the same user your file manager is using when you double click on the file? – SharkofMirkwood Mar 10 '16 at 12:37
  • How do you determine "the directory where the jar file resides" ? Note that this is not necessarily the same as the current working directory. – Thilo Mar 10 '16 at 12:38
  • @SharkofMirkwood, Yes. – user3516726 Mar 10 '16 at 13:01
  • @Thilo, As I said, if I cd to the directory that contains the jar file, and run it from the command line, it works fine and produces an output file in that same directory. If I try running the jar file by double clicking its icon, everything works fine, except that there is no output file. – user3516726 Mar 10 '16 at 13:03
  • suppose that as you are using ubuntu OS , you ll have the Open JDK version. You can go at the control panel and Open Java configuration. In advanced tab there is a radio button Show / Hide Console. Select show console , and the doucle click again your jar file. It should open a terminal when your app get started. Try write the file you want and check if it throws any exceptions in your console – AntJavaDev Mar 10 '16 at 13:05
  • `new File("")` will give you the current working directory. This is not the directory of the jar file (unless you `cd` there first). – Thilo Mar 10 '16 at 23:46
  • I got an answer mailed to me that works. [See this link-](http://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file) – user3516726 Mar 11 '16 at 16:29

1 Answers1

0

I think Source File Doesn't Contain Full path of Output file.. Please Check file path and then run your jar file.