This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes finding certain files in a jar using ClassLoader.getResources() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "finding certain files in a jar using ClassLoader.getResources()" Watch "finding certain files in a jar using ClassLoader.getResources()" New topic
Author

finding certain files in a jar using ClassLoader.getResources()

Stuart Rogers
Ranch Hand

Joined: Oct 02, 2008
Posts: 133
I've built a Java/Hibernate/Swing standalone app that works great when executed from within Eclipse.
I created a runnable jar, in which the GUI part worked but the app stalled when the "DoIt" JButton was clicked.
After a great deal of googling I have a vague understanding that the problem lies with classloaders, and that
one solution is to use ClassLoader.getResource() and/or ClassLoader.getResources()

I know these files are contained in the root directory of the runnable jar:
lamp.cfg.xml
sofa.cfg.xml
desk.cfg.xml

which is to say they are located in the /src directory of my Eclipse project.

a snippet of my HibernateUtil.java:


I don't want to have to hardcode filenames - I want the code to find them, either by the regex used in the third Enumeration or by iterating through all the files in the root directory of the jar and picking out the desired files.

So how can I get
a) ClassLoader.getResources() to return a list (well, enum) of just the files in the root directory of the jar that I want, using the regex
b) ClassLoader.getResources() to return a list (well, enum) of all the files in the root directory of the jar


TIA,

Still-learning Stuart
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37941
    
  22
Too difficult a question for us who are "beginning". Moving discussion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: finding certain files in a jar using ClassLoader.getResources()
 
Similar Threads
split a file to original files
While replacing char of soap response then it throws error
log4j -> fileAppender.getFile() to read unix log dir location
package javax.servlet.annotation does not exist
Getting the path of file selected in JTree item