Eclipse export file jar doesn't contain folder

user1431148

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

Etienne Miret

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Spring Boot JAR doesn't contain classes in src folder

From Dev

Export as Executable Jar File in Eclipse

From Dev

Java export a folder next to jar in eclipse

From Dev

Java export a folder next to jar in eclipse

From Dev

Include text file in Eclipse JAR export?

From Dev

shared folder doesn't contain data

From Dev

Eclipse: Export .JAR on save

From Dev

Eclipse export to runnable .jar

From Dev

Eclipse RCP doesn't unpack jar

From Dev

Eclipse doesn't recognize jar method

From Dev

Import of excuting jar doesn't work in eclipse

From Dev

Parse CSV = file doesn't contain a string

From Dev

Scala and Eclipse: Export as Jar File, but cannot find main method

From Dev

Eclipse Java9 Export Runnable JAR file

From Dev

Scala and Eclipse: Export as Jar File, but cannot find main method

From Dev

Eclipse-Android-SDK: DDMS: File-Explorer doesn't open folder

From Dev

Selected folder doesn't contain a config.xml in phonegap

From Dev

Selected folder doesn't contain a config.xml in phonegap

From Dev

Glassfish 3.1.2 doesn't contain javax.persistence jar

From Dev

java - Eclipse won't export with declared source folder

From Dev

why eclipse not detect the jar file from lib folder

From Dev

Export-Csv doesn't create a file

From Dev

Export resource in jar file

From Dev

Export as an executable jar file

From Dev

File doesn't get uploaded in folder php

From Dev

Refreshing a folder that doesn't exist in the file system

From Dev

File doesn't get uploaded in folder php

From Dev

Gradle doesn't import jsoup into jar file

From Dev

Jar file doesn't load prolog