I have developed a GUI application in NetBeans (v. 7.2.1) on Mac (OS version 10.6.8). This application requires an XML file (containing data used by the program), which I would like to place in a subdirectory data
.
The trouble is that if I want to run my application from within NetBeans, this data directory has to be placed inside the main project directory; however, if I want to simply run the .jar
file (using a doubleclick), located in the dist
subdir of the main dir, I have to move the data folder into dist
- and then the program will no longer run from within NetBeans.
This is how the data file path is specified within the program:
public String vocabPath = "data" + File.separator + "wordlist.xml";
public File vocabFile = new File(vocabPath);
In itself at first this did not seem problematic, as, for redistribution of the application, I thought I could simply move the data directory into dist
, and distribute that (which worked fine on OS X and Windows 7); however, on Ubuntu I got an error message saying the data file was not found.
I am new to Java, so perhaps this is a daft question, but anyway: how can I get my application to always access the data file located in MAIN_DIR/dist/data
? Or if the root of the problem lies somewhere else, then please let me know.
Thanks a lot in advance!
EDIT
I have posted a follow-up question, as I think I have narrowed down the problem to some unexpected behaviour which only occurs under Ubuntu.
EDIT 2
An answer to my follow-up question (see first edit) has solved my problem (just as a note to those who've found this post while trying to solve a problem similar to mine).