Instead of hardcoding, you can define a variable in
the web.xml as

<context-param>
        <param-name>jndiproperties</param-name>
       
<param-value>relativepathtowebapp/jndi.properties</param-value>
        <description>jndi properties</description>
    </context-param>

and get the path name from the servlet context real
path as follows.

String propsFilePath =
ServletContext.getRealPath(ServletContext.getInitParameter("jndiproperties"));


Once you have the file path, then you can read using 
FileInputStream.

FileInputStream in = new
FileInputStream(propsFilePath);
Properties props = new Properties();
props.load(in);

-Sreeni.




--- David Smith <[EMAIL PROTECTED]> wrote:

> Or better yet, use
> ServletContext#getResourceAsStream() as follows:
> 
> Properties jndiProps = new Properties() ;
> try {
>   jndiProps.load(
> getServletContext().getResourceAsStream(
> "/any/webapp/relative/folder/jndi.properties" ) ) ;
> } catch ( IOException ioe ) {
>   // Log and handle error
> }
> 
> This works whether the file is in a war or a webapp
> folder.  The code
> above assumes you are executing from a servlet or
> jsp.
> 
> --David
> 
> abdurrahman sahin wrote:
> 
> >i never tried it with default ctor, used it as 
> >new InitialContext(jndiProperties);
> >using DirectoryFinding methods may help you like
> below.
> >String realPath =
> request.getRealPath(request.getContextPath());
> >That should return the path up to where you have
> your servlet context. 
> >
> >
> >
> >-----Original Message-----
> >From: Feris Thia [mailto:[EMAIL PROTECTED]
> >Sent: Wednesday, May 03, 2006 3:56 PM
> >To: Tomcat Users List;
> [EMAIL PROTECTED]
> >Subject: Re: jndi.properties
> >
> >
> >Ic.... so we cannot just load it from the directory
> where jsp are and
> >use this code ?
> >
> >=====================================
> >InitialContext jndiContext = new InitialContext();
> >=====================================
> >
> >On 5/3/06, abdurrahman sahin
> <[EMAIL PROTECTED]> wrote:
> >  
> >
> >>i think , it is actully related to where you are
> looking for.
> >>i think you can put it anyware as long as the
> diretory you put it is
> >>accessible.
> >>
> >>http://asahin.net
> >>
> >>private static final String
> CONFIG_FILE="resources/jndi.properties";
> >>FileInputStream fis = new
> FileInputStream(CONFIG_FILE);
> >>                        myProperties.load(fis);
> >>
> >>
> >>    
> >>
> >
> >
> >--
> >Regards,
> >Feris
> >PT. Putera Handal Indotama
> >JL. KH. Moh. Mansyur No. 11 Blok B.8-12
> >Telp. +62-21-631 6688 (Hunting)
> >Fax. +62-21-6330211
> >Jakarta (10140) - INDONESIA
> >
>
>---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> >For additional commands, e-mail:
> [EMAIL PROTECTED]
> >
> >
> >
>
>---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> >For additional commands, e-mail:
> [EMAIL PROTECTED]
> >
> >  
> >
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to