Jar file ADD DIRECTORY ENTRIES Eclipse option when exporting a jar

I do not ask the right question or not, but I want to remove my doubts.

Actually, I came across a script for accessing class files from a jar file. I want to say that I have one backend java project that says ABC with application-context.xml file.

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

Here, I ran into a beans problem not getting Autowired, and found out that the problem was, When I export the ABC project jar file using Eclipse, I did not select the “ADD RECORD GUIDES”, which I did later and everything worked.

to see what changes have been made by checking this box in the jar file so that everything works,

So, I created 2 jar files, one of which is marked as "ADD DIRECTORY ENTRIES", and one with unchecked, then I compared both jars using out of comparison, and found that there is no difference.

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

I know that it should add a full structure instead of a single path, for example com / company / project / MyJavaFile.class

com / company /

com / company / project /

com / company / project / MyJavaFile.class

Please correct me if I am wrong.

+6
source share
3 answers

You must enable "Add Directory Entries" when creating jar files if you need to use the class.getResource () method to get the URI of a specific directory inside your jar file. The reason you want to do this is to save the URIs in your resource folder, for example.

If you use class.getResource () to get the URI of a specific file [rather than a directory], then you'll be fine if you leave "Add Entries to the Directory".

+6
source

Doc JAR File Exporter Form

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

+2
source

If you look at a jar file with 7-zip or something similar, you will see that there is a “D” attribute for folders when “Add entries to directory” is selected. These attributes do not exist when this parameter does not exist. Your comparison probably compared the contents of the files in the jar file and did not consider the attributes of the jar file.

0
source

All Articles