Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jar file ADD DIRECTORY ENTRIES Eclipse option while exporting jar

I don't whether I am asking correct question or not but want to clear my doubt.

Actually I came across the scenario of referring class files from jar file. I mean to say I have one backend java project say ABC with application-context.xml file in it.

Now I created jar file of ABC project and used in one web based application.

Here I am facing a problem of beans not getting Autowired and came to know the problem was, When I export the jar file of ABC project using Eclipse, I have not selected "ADD DIRECTORY ENTRIES" checkbox which later on I did and all worked.

just to see what changes has been made by checking this box in a jar file so that all worked,

So I created 2 jar files one with "ADD DIRECTORY ENTRIES" checked and one with unchecked, then I compared both jar using beyond compare and found there is no difference at all.

Can someone explain me what exactly "ADD DIRECTORY ENTRIES" does?

what I know is it should add complete structure instead of single path like com/company/project/MyJavaFile.class

com/company/

com/company/project/

com/company/project/MyJavaFile.class

Please correct me if I am wrong.

like image 289
Jayesh Avatar asked Nov 06 '12 06:11

Jayesh


3 Answers

You should enable "Add directory entries" when creating jar files if you need to use class.getResource() method to get the URI of a particular directory inside your jar file. The reason why you may want to do this is to hold a URI to your "resource" folder for example.

If you only use class.getResource() to get the URI of a specific file [and not a directory] then you will be fine if you leave the "Add directory entries" off.

like image 107
Saeid Nourian Avatar answered Nov 10 '22 14:11

Saeid Nourian


Form Doc JAR File Exporter

Add directory entries: adds an entry for each directory to the JAR file, even if the directory does only contain subdirectories.

like image 38
Sumit Singh Avatar answered Nov 10 '22 14:11

Sumit Singh


If you look at the jar file with 7-zip or something similar, you can see that there is a "D" attribute for the folders when "Add directory entries" is selected. These attributes do not exist when that that option does not exist. Your compare was probably comparing the contents of the files within the jar file and wasn't looking at the jar file attributes.

like image 42
David McMillan Avatar answered Nov 10 '22 12:11

David McMillan