tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: Classloader issue
Date Sat, 16 Dec 2000 19:16:47 GMT
Try using ClassLoader.getResourceAsStream() instead of
ClassLoader.getSystemResourceAsStream().  The method you are using says "go use
the system class loader", and bypasses any resources that are in your jar file
under WEB-INF/lib.

Craig McClanahan



Juergen Baumann wrote:

> I try to load files in an InputStream (using ClassLoader) in the init() method
> of a Servlet that is loaded on startup. The files reside in a .jar file that
> contains all the classes as well.Using ClassLoader works fine in a stand-alone
> application, however, as soon as I try to make it work together with Tomcat
> using Servlets, I get the message: cannot load Servlet: ...Here is the
> relevant code. Thanks a lot in advance,JB  init() method of
> Servlet:-------------------------...try {
>   Items items_F = new Items("test1");  context.setAttribute(Items.F_KEY,
> items_F);
>  } catch (IOException e) {
>   context.log("No item property file" , e);
>   return;
>  }.... Items class:------------ public Items(String name) throws IOException
> {  this.items = new Properties();
>  InputStream is;  if (name.equals("text1") ) {
>   is = ClassLoader.getSystemResourceAsStream("items/items.text1");
>  } else if (name.equals("text2") ) {
>   is = ClassLoader.getSystemResourceAsStream("items/items.text2");
>  }...
>  this.items.load(is);
>  is.close();
> }

Mime
View raw message