File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Does Classloader loads normal files from dir in a JAR file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Does Classloader loads normal files from dir in a JAR file" Watch "Does Classloader loads normal files from dir in a JAR file" New topic
Author

Does Classloader loads normal files from dir in a JAR file

naresh pokuri
Greenhorn

Joined: Feb 13, 2010
Posts: 10
what is the nature of Classloader, when a JAR file contains a dir named pref folder with .properties files and other xml files.
can we get reference to that files as stream by passing file names to ClassLoader.getReasourceAsStream() method.
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
naresh pokuri wrote:what is the nature of Classloader, when a JAR file contains a dir named pref folder with .properties files and other xml files.
can we get reference to that files as stream by passing file names to ClassLoader.getReasourceAsStream() method.

Yes, we can.
You could pack to jar file whatever you want - images, properties, icons, text files, other jars, even database files.
If you want to retrieve resources from your application's jar file, try this example:


If you want to read file from other jar, try this:

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

naresh pokuri wrote:what is the nature of Classloader, when a JAR file contains a dir named pref folder with .properties files and other xml files.
can we get reference to that files as stream by passing file names to ClassLoader.getReasourceAsStream() method.

Just for future reference, it would have been quicker to just try it!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Does Classloader loads normal files from dir in a JAR file
 
Similar Threads
Applet runs only if class file is in the same dir
java.lang.Class NotFoundException
Jar Tag (put libraries in Jar file).
Hssf error
how to include jar in jar