I have created a runnable jar with eclipse. Inside my project I have a folder called questionnaire which contains some text files I use. When I run my runnable jar it doesn't work except if I have in the same folder as the jar the folder questionnaire. I tried some solutions that I read in stackoverflow like add folder questionnaire as a source folder and also from properties -> java build path -> libraries ->Add class folder and add questionnaire folder but still doesn't work.
This is the code:
File srcFolder = new File(".\\questionnaire");
if(!srcFolder.exists()){
System.out.println("Directory does not exist.");
//just exit
System.exit(0);
}
And every time I get message "Directory does not exist". Also when I unzip the jar there is no folder questionnaire
To add the folder "questionnaire" into your jar, you need to set the parent directory of "questionnaire" as a source folder.
Then, you'll have a questionnaire "folder" into your jar. However, you won't be able to access it via the File API, since it won't be a regular folder but an entry into your jar. If you simply need to read files from that folder, have a look at the Class.getRessourceAsStream(String) method.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments