views:

50

answers:

2

I'm building a project with ant and during the build I'd like to bundle a number of property/config files directly into the .jar to make distribution simpler. I've been successful in adding these files to the .jar, but I'm unable to load them in my program.

What is the procedure to open/read a file that's been bundled into a .jar file?

+4  A: 

Use the getResourceAsStream method on class:

Properties p = new Properties();
p.load(MyClass.class.getResourceAsStream("/myprops.properties"));
Karl Johansson
Perfect, thanks!
digitala
+1  A: 

You can load those by using the ClassLoader getResourceAsStream() method.

rsp