tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Collins, Jim" <jim.coll...@uk.nomura.com>
Subject RE: still problem to load a property file in tomcat4.1.24???
Date Wed, 14 May 2003 10:33:21 GMT
Don't use the classloader. Use
ServletContext.getResourceAsStream("/WEB-INF/classes/myFile");

Regards

Jim.

> >Hi,
> >
> >I have written a simple jsp page and in that i am trying to 
> load a config
> >file for my application
> >
> >Properties prop = new Properties();
> >try
> >{
> >                 InputStream fin =
> >ClassLoader.getSystemResourceAsStream("Shyam.config");
> >                 prop.load(fin);
> >                 System.out.println("File Loaded Successfully");
> >         }
> >         catch(Exception e)
> >         {
> >                 e.printStackTrace();
> >         }
> >}
> >
> >But this is giving error as its not able to load 
> Shyam.config file. which is
> >in WEB-INF/classes folder in my application.
> >
> >Please show me a way.
> >
> >Thanks
> >
> >Pawan
> >
> >
> >-----Original Message-----
> >From: Shapira, Yoav [mailto:Yoav.Shapira@mpi.com]
> >Sent: Tuesday, May 13, 2003 6:47 PM
> >To: Tomcat Users List; pawan.s@apar.com
> >Subject: RE: how to load a property file in tomcat4.1.24???
> >
> >
> >
> >Howdy,
> >RTFM:
> >http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-
> howto.html
> >
> >Or search the archives.
> >
> >WEB-INF/classes is automatically on the "classpath" for your 
> webapp and
> >JSP.  You don't need to modify the classpath environment variable nor
> >any of the classpaths in tomcat's startup scripts.
> >
> >Yoav Shapira
> >Millennium ChemInformatics
> >
> >
> > >-----Original Message-----
> > >From: pawan [mailto:pawan.s@apar.com]
> > >Sent: Tuesday, May 13, 2003 9:12 AM
> > >To: 'Tomcat Users List'
> > >Subject: how to load a property file in tomcat4.1.24???
> > >
> > >Hello Everyone,
> > >
> > >in my application's web-inf/classes folder i have a package named
> >"common"
> > >in that i have a file "Alerter.java"
> > >
> > >in which i am loading a property file in static block, by using the
> > >ClassLoader.. now to load ALERT_CONFIG_FILE this file should eb in
> > >classpath. so i have set the classpath to
> > >
> > >C:\jakarta-tomcat-4.1.24\webapps\shyam\WEB-INF\classes
> > >
> > >and i have put my file Shyam.config in there. But its 
> giving error when
> >i
> > >call this class by a jsp page in tomcat.
> > >
> > >Its working file if i use command line argument e.g.
> > >C:\jakarta-tomcat-4.1.24\webapps\shyam\WEB-INF\classes>java
> >common.Alerter
> > >
> > >I think i need to set the CLASSPATH variable for tomcat 
> window where
> >all
> > >console output comes.
> > >
> > >Please help me how i can make it work?? Or is there any other
> >alternative??
> > >
> > >Thank you in advance.
> > >
> > 
> >*************************************************************
> **********
> > >Here is a part of source code
> > 
> >*************************************************************
> **********
> > >
> > >
> > >private static final String ALERT_CONFIG_FILE ="Shyam.config";
> > >
> > >static
> > >       {
> > >        try
> > >               {
> > >            cfg =  getAlertConfig();
> > >               }
> > >               catch(Exception e){}
> > >    }
> > >
> > > public static Properties getAlertConfig() throws IOException
> > >       {
> > >
> > >               Properties prop = new Properties();
> > >               try
> > >               {
> > >                       InputStream fin =
> > >ClassLoader.getSystemResourceAsStream(ALERT_CONFIG_FILE);
> > >                       prop.load(fin);
> > >                       System.out.println("File Loaded 
> Successfully");
> > >               }
> > >               catch(Exception e)
> > >               {
> > >                       System.out.println("Either ALERT 
> Configuration
> >file: '"
> > >+ALERT_CONFIG_FILE+"' Not found in CLASSPATH or it can not 
> be read");
> > >               }
> > >               System.out.println("........"+prop);
> > >               return prop;
> > >    }
> > >
> > >
> > 
> >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: 
> tomcat-user-help@jakarta.apache.org
> >
> >
> >
> >
> >This e-mail, including any attachments, is a confidential business
> >communication, and may contain information that is 
> confidential, proprietary
> >and/or privileged.  This e-mail is intended only for the 
> individual(s) to
> >whom it is addressed, and may not be saved, copied, printed, 
> disclosed or
> >used by anyone else.  If you are not the(an) intended 
> recipient, please
> >immediately delete this e-mail from your computer system and 
> notify the
> >sender.  Thank you.
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 


PLEASE READ: The information contained in this email is confidential
and intended for the named recipient(s) only. If you are not an intended
recipient of this email you must not copy, distribute or take any 
further action in reliance on it and you should delete it and notify the
sender immediately. Email is not a secure method of communication and 
Nomura International plc cannot accept responsibility for the accuracy
or completeness of this message or any attachment(s). Please examine this
email for virus infection, for which Nomura International plc accepts
no responsibility. If verification of this email is sought then please
request a hard copy. Unless otherwise stated any views or opinions
presented are solely those of the author and do not represent those of
Nomura International plc. This email is intended for informational
purposes only and is not a solicitation or offer to buy or sell
securities or related financial instruments. Nomura International plc is
regulated by the Financial Services Authority and is a member of the
London Stock Exchange.



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message