You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Feris Thia <fe...@gmail.com> on 2006/05/03 14:34:57 UTC

jndi.properties

Hi,

I try to put jndi.properties under the same folder with JSP page. But
it's not working. Where should I put it ?

--
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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jndi.properties

Posted by Feris Thia <fe...@gmail.com>.
ic... i think this is what i need.

thx,

feris

On 5/3/06, abdurrahman sahin <ab...@argela.com.tr> 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.
>
>
>

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


Re: jndi.properties

Posted by Feris Thia <fe...@gmail.com>.
Hi Tim,

I've read the article..... I think I get all the ideas..... In Tomcat
should be in classloader path right ? like in lib or classes folder ?
I'll try that.

Thanks

On 5/3/06, Tim Lucia <ti...@yahoo.com> wrote:
> No.  It has to be under a location accessible via the classpath.  The JSPs
> are web content.  Read this:
>
> http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html
>
> Tim
> --
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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jndi.properties

Posted by Marc Farrow <ma...@gmail.com>.
Probably a Java expert could help more, but I think you can use a
ResourceBundle (and place the properties in your package with your java
class files) to retrieve it or even a URL to load the properties file.

URL method psuedo code:
Properties props = new Properties();
URL url = new URL(http://localhost:8080/mywebapp/test.properties);
props.load(url.openStream());
//props.load(InputStream is) is the method defintion so any InputStream will
work

ResourceBundle psuedo code:
ResourceBundle myResource = ResourceBundle.getBundle("
com.yourcompany.yourpackage.jndi");
String myProperty = myResource.getString("mypropertyname");



On 5/3/06, Feris Thia <fe...@gmail.com> wrote:
>
> 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 <ab...@argela.com.tr> 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: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>


--
Marc Farrow

RE: jndi.properties

Posted by Tim Lucia <ti...@yahoo.com>.
No.  It has to be under a location accessible via the classpath.  The JSPs
are web content.  Read this:

http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html 

Tim

-----Original Message-----
From: Feris Thia [mailto:feris.tia@gmail.com] 
Sent: Wednesday, May 03, 2006 8:56 AM
To: Tomcat Users List; abdurrahman.sahin@argela.com.tr
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 <ab...@argela.com.tr> 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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



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


Re: jndi.properties

Posted by Feris Thia <fe...@gmail.com>.
ic.... It works ...

This is the best approach that I may Used....

Thanks Sreeni ..

On 5/4/06, Sreenivasulu R Gaddam <ga...@yahoo.com> wrote:
> 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.
>

--
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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: jndi.properties

Posted by Sreenivasulu R Gaddam <ga...@yahoo.com>.
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 <dn...@cornell.edu> 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:feris.tia@gmail.com]
> >Sent: Wednesday, May 03, 2006 3:56 PM
> >To: Tomcat Users List;
> abdurrahman.sahin@argela.com.tr
> >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
> <ab...@argela.com.tr> 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:
> users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail:
> users-help@tomcat.apache.org
> >
> >
> >
>
>---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail:
> users-help@tomcat.apache.org
> >
> >  
> >
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail:
> users-help@tomcat.apache.org
> 
> 


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

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


Re: jndi.properties

Posted by David Smith <dn...@cornell.edu>.
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:feris.tia@gmail.com]
>Sent: Wednesday, May 03, 2006 3:56 PM
>To: Tomcat Users List; abdurrahman.sahin@argela.com.tr
>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 <ab...@argela.com.tr> 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: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>
>  
>


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


RE: jndi.properties

Posted by abdurrahman sahin <ab...@argela.com.tr>.
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:feris.tia@gmail.com]
Sent: Wednesday, May 03, 2006 3:56 PM
To: Tomcat Users List; abdurrahman.sahin@argela.com.tr
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 <ab...@argela.com.tr> 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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



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


Re: jndi.properties

Posted by Feris Thia <fe...@gmail.com>.
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 <ab...@argela.com.tr> 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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: jndi.properties

Posted by abdurrahman sahin <ab...@argela.com.tr>.
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);



-----Original Message-----
From: Feris Thia [mailto:feris.tia@gmail.com]
Sent: Wednesday, May 03, 2006 3:35 PM
To: users@tomcat.apache.org
Subject: jndi.properties


Hi,

I try to put jndi.properties under the same folder with JSP page. But
it's not working. Where should I put it ?

--
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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



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