Thanx Yoav, Great! The latter is exactly what I want to do.....So when I want to use the properties after they have been bound, I would do something like:
InitialContext ctx = new InitialContext(); Object obj = (Object)ctx.lookup("java:/comp/env/myJndiRef"); Or something to that affect...... Is there a best practice for this? I would like to see all of my app config stuff in one XML file......so when I deploy the app between (dev --> staging --> production) it goes smoothly without having to rewrite any classes..... Russ -----Original Message----- From: Shapira, Yoav [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 17, 2003 8:51 AM To: Tomcat Users List Subject: RE: Tomcat and Initial Naming Howdy, The java:/comp/env context is special in that it's defined by the servlet specification is the location for "environment" properties defined in the server. So whatever you define in server.xml/web.xml will go in that context. A servlet container is not required by the spec to give you runtime write permission to that context. In practice, however, nearly all do. You have two options roughly, one's easier but doesn't allow XML, and the other is the opposite: 1. Instead of an XML file for your webapp, name the file jndi.properties and place it in WEB-INF/classes. It will be automatically available in your environment context. 2. If you want to use an XML file, you need to parse it yourself and use Context#bind(...) or Context#addToEnvironment(...) to populate the naming context with your properties. Yoav Shapira Millennium ChemInformatics >-----Original Message----- >From: Pitre, Russell [mailto:[EMAIL PROTECTED] >Sent: Tuesday, September 16, 2003 6:15 PM >To: Tomcat Users List >Subject: Tomcat and Initial Naming > >I'm trying to understand naming contexts and their implementations in >tomcat.....looking at the code below, we lookup the jndi resource >"jdbc/test" When tomcat starts up, it parses the server.xml file.....It >finds: > > > <Resource name="jdbc/test" auth="Container" >type="javax.sql.DataSource"/> > <ResourceParams name="jdbc/test"> > <parameter> > <name>factory</name> > <value>org.apache.commons. > >dbcp.BasicDataSourceFactory</value> > </parameter> > . > . > . >Tomcat looks at this and adds a name value pair to a naming >context.....My question is about this naming context tomcat has......How >can I add a name value pair to this same context?.....and how can I make >a reference to that value? Would I access it the sameway in the code >below? (("java:/comp/env/"myRefernceName") or ("java:/") ) I want to >add other values to this same context....My basic idea is to have an xml >file with all of the properties for my webapp....and I want to lookup >these properties using jndi.....my reason for this is I want to be able >to lookup certain application specific properties (i.e. ldap stuff, jdbc >stuff, constants, and such.....and I know about adding jdbc, and ldap >res-ref in the server.xml) much like a myApp.properties file......Any >ideas? Does this question make sense...... > > > > >try { > Context ctx = new InitialContext(); > > if (ctx == null) > throw new Exception("Boom - No Context"); > > DataSource ds = >(DataSource)ctx.lookup("java:comp/env/jdbc/test"); > > out.println ("DATASOURCE: " + ds); > > conn = ds.getConnection(); > > . > . > . > }catch{...... > > >Thanx in advance >Russ > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]