Return-Path: Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 38769 invoked from network); 16 Dec 2000 19:15:18 -0000 Received: from lukla.sun.com (192.18.98.31) by locus.apache.org with SMTP; 16 Dec 2000 19:15:18 -0000 Received: from centralmail1.Central.Sun.COM ([129.147.62.10]) by lukla.Sun.COM (8.9.3+Sun/8.9.3) with ESMTP id MAA01093 for ; Sat, 16 Dec 2000 12:15:18 -0700 (MST) Received: from esun1as-mm. (esun1as-mm.Central.Sun.COM [129.147.34.144]) by centralmail1.Central.Sun.COM (8.9.3+Sun/8.9.3/ENSMAIL,v1.7) with SMTP id MAA07946 for ; Sat, 16 Dec 2000 12:15:17 -0700 (MST) Received: from eng.sun.com by esun1as-mm. (SMI-8.6/SMI-SVR4) id MAA27368; Sat, 16 Dec 2000 12:29:30 -0700 Message-ID: <3A3BBF9F.BDC29670@eng.sun.com> Date: Sat, 16 Dec 2000 11:16:47 -0800 From: "Craig R. McClanahan" X-Mailer: Mozilla 4.76 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: tomcat-user@jakarta.apache.org Subject: Re: Classloader issue References: <000c01c0668b$3d25f940$5b0aa8c0@Permit> Content-Type: multipart/alternative; boundary="------------3569E3E4A12642A3F377EA16" X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N --------------3569E3E4A12642A3F377EA16 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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(); > } --------------3569E3E4A12642A3F377EA16 Content-Type: text/html; charset=us-ascii Content-Transfer-Encoding: 7bit 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();
}
--------------3569E3E4A12642A3F377EA16--