Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
716 views
in Technique[技术] by (71.8m points)

java - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...