4

I need to create an application for sorting various types of polygons using various parameters such as height, volume or base area. Arguments for Filename which has parameters for polygons, Sort type, Sort method will be pass through command line.That file is in my resource folder outside my src folder in a project. I have implemented all programs, It works fine when I run using pass arguments through eclipse run configuration. But when I try to run my .jar file using cmd same arguments it gives me FileNotFoundException.

I opened my jar file using 7zip and noticed it never extracted my resource folder in .jar file. I searched online and tried including my resource folder in to build path of eclipse. But still does't work.

enter image description here

Wilson Vargas
  • 2,841
  • 1
  • 19
  • 28
S.P
  • 43
  • 2
  • 2
  • 7
  • Is the resources folder checked in "Order and Export" tab in "Java Build Path"? – Vasan Nov 03 '17 at 16:47
  • Yes, I just checked it. It is checked and exporting into jar file but now it is exporting all files separately, not as a folder. Thanks for your reply. – S.P Nov 03 '17 at 16:54
  • Try selecting "Add directory entries" in the Eclipse export dialog (the screen where you enter JAR file name) – Vasan Nov 03 '17 at 17:03

3 Answers3

2

Follow these steps:

1) click project -> properties -> Build Path -> Source -> Add Folder and select resources folder.

2) create your JAR!

EDIT: you can make sure your JAR contains folder by inspecting it using 7zip.

Reefer this link as well How do I add a resources folder to my Java project in Eclipse

arjunsv3691
  • 791
  • 6
  • 19
  • Thank you for reply. I just tried it. But it add files separately instead of resources folder. And still FileNotFoundException occurs. – S.P Nov 03 '17 at 17:40
  • After following your EDIT tip, I learned that even though your resource file, e.g. `someFile.txt` is located in `/src/main/resource//someFile.txt`, the location you have to access it at, is: `/someFile.txt`. (As one can see after inspecting the `.jar` file with winrar/7zip. – a.t. Jul 31 '19 at 16:28
1

First, you need to create a source folder for resources, for instance name it res, and then move your image folder to res. When you generate the jar file, you will see the image folder, not the res folder or files separately.

resource folder

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Farnaz
  • 11
  • 1
0

This comes down to how you are generating the JAR file.

When you're exporting the jar in eclipse make sure to checkbox the button that says "Export java sources and resources" https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/ensureJavaFiles.jpg

There are a lot of ways to do this one is to use Gradle is the recommended way, something like this will work Creating runnable JAR with Gradle

visch
  • 707
  • 5
  • 23