0

How to load (from code) required file (*.txt) from WEB-INF\lib\someName.jar?

I tried mechanism:

this.getClass().getClassLoader().getResourceAsStream(<nameFile>).

But it worked only when required file was in WEB-INF\classes folder.
Then i tried to create META-INF\resources folder in jar with required file. But it didn't give effect.

slider
  • 421
  • 1
  • 4
  • 19
  • Why bother going all the way to the classloader? You could've just stopped at the class. – kolossus Jun 19 '14 at 15:50
  • possible duplicate of [Loading resources (images) contained in a .Jar file or in the classpath](http://stackoverflow.com/questions/22203162/loading-resources-images-contained-in-a-jar-file-or-in-the-classpath) – robermann Jun 19 '14 at 16:11

1 Answers1

0

Try getResourceAsStream method on the Class instead of ClassLoader.

this.getClass().getResourceAsStream(<nameFile>).

Just tested it this way and I got an instance of sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream@89fbe3

Aragorn
  • 5,021
  • 5
  • 26
  • 37