tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allistair Crossley" <Allistair.Cross...@QAS.com>
Subject RE: jndi question
Date Tue, 23 Aug 2005 16:27:20 GMT
Hi,

He isn't using that method of configuration, that's just 1 option of 3. He is nesting his
Context definition within the server.xml Host element. Although this is now scorned, it's
still valid. The 2 other methods are contextname.xml as you say, and also META-INF/context.xml
within the webapp itself. 
Allistair.

> -----Original Message-----
> From: Brian Cook [mailto:bcook@printtime.com]
> Sent: 23 August 2005 17:23
> To: Tomcat Users List
> Subject: Re: jndi question
> 
> 
> 
> Ok but do you have the resource defined in context.xml?  If you go to 
> <<Tomcat Dir>>/conf/Cataliana/localhost/ do you see a file 
> with the name 
> of the module ending with .xml?  If so is the resource 
> defined in that 
> file?  If not you need to add it.
> 
>  From the description it sounds like nothing in this set up has been 
> done as was show on the example page.
> 
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources
> -howto.html
> 
> If you use the code block that is shown, define that resource 
> in web.xml 
> and context.xml it will work.  But multiple postings latter it still 
> sounds like the JNDI resource is not defined in context.xml 
> and the code 
> calling the JNDI resource differs greatly from the example provided.
> 
> 
> Sean Rowe wrote:
> > The first post on this included the server.xml, and further 
> down in the 
> > page is the relevant part of web.xml ( i just double 
> checked that ).  as 
> > for context.xml, i have listed it in my webapp.xml file, as well as 
> > server.xml as all other examples have suggested.  i then 
> tried it in the 
> > admin module, where it then put it in server.xml for me.  
> i'm willing to 
> > try anything at this point, though, if you have any suggestions.
> > 
> > as for my post not being jndi specific, i applogize if 
> that's the case.  
> > i'm not really familiar with jndi....but when I did a search for 
> > 'connection pooling', jndi seemed to be what everyone 
> suggested i use.  
> > what i want to do, if it's not clear, is to create a 
> connection pool to 
> > my MySql database.
> > thanks,
> > sean
> > 
> > Brian Cook wrote:
> > 
> >>
> >> Actually the files I listed are NOT in the first post.  It 
> shows the 
> >> server.xml and the code calling it but does not show web.xml or 
> >> context.xml.
> >>
> >> The error you are getting just means that that the JNDI 
> resource being 
> >> called in the code is not defined in both web.xml and context.xml.
> >>
> >> In looking at the code snip it in the first post I am not 
> following 
> >> what you are trying to do.  The post is for a JNDI 
> question but in the 
> >> code it looks like you are calling the DB URL directly.  The whole 
> >> point of JDNI being to get specific URL, and configuration info 
> >> outside of the code base.  I am not following what it is you are 
> >> trying to do here.
> >>
> >>
> >>
> >> Sean Rowe wrote:
> >>
> >>> Brian, thank you for replying.  I was afraid my topic was 
> dead.  If 
> >>> you could look at my first post, I listed all the files 
> that you have 
> >>> suggested I take a look at.  I have done everything you have 
> >>> suggested, but am still getting errors.  The error I am 
> getting now is
> >>>
> >>> javax.naming.NameNotFoundException: Name java:comp is not 
> bound in 
> >>> this Context
> >>>
> >>> I can't find anything on the net or in any books I've 
> looked at that 
> >>> explains this.  As far as I can tell, java:comp should just be 
> >>> there.  Any ideas?  Thanks again.
> >>>
> >>> Sean
> >>>
> >>> Brian Cook wrote:
> >>>
> >>>>
> >>>> Yes you can use JNDI with out using JSTL.  But the only way to 
> >>>> configure it is to define the JNDI resources in the web.xml and 
> >>>> context.xml files.    Technically you should be able to use the 
> >>>> globally defined JNDI resources in server.xml, and I have seen 
> >>>> configuration set ups doing it when googling.  But could 
> never get 
> >>>> them to work.
> >>>>
> >>>> This highlights another area of seemingly unneeded 
> complication in 
> >>>> Java/Unix development.  Using JNDI for data sources which was 
> >>>> supposed to help you save time requires that you 
> redundantly define 
> >>>> the JNDI resource in at lest 2 if not 3 places.
> >>>>
> >>>> The admin tool which was also supposed to help save time 
> defines the 
> >>>> JNDI resources in server.xml which does not really seem 
> to be all 
> >>>> that helpful.  I am sure there is likely a reason for 
> this but I am 
> >>>> ignorant of it.  The admin tool is also supposed to let 
> you define 
> >>>> JNDI resources  per context but it errors out when ever 
> I have tried 
> >>>> it.
> >>>>
> >>>> My experience with the Tomcat Admin and Manager tools is 
> that they 
> >>>> are worthless.  Of the few steps they try to help with 
> more often 
> >>>> that not they just return errors when you need to use 
> it.  I removed 
> >>>> them both and have gone back to doing set ups manually 
> and there has 
> >>>> not been much of a time difference doing it this way.
> >>>>
> >>>> Any way for JNDI to work you will have to add the 
> definition for it 
> >>>> in both web.xml and context.xml in the <<Tomcat 
> >>>> Folder>>/conf/Catalina/localhost/ folder.  This seems counter

> >>>> productive since it makes your app less portable having the data 
> >>>> base configuration details inside the context and by 
> extent the WAR 
> >>>> file but it is what you have to do to get it to work right now.
> >>>>
> >>>> I feel your pain I know it is frustrating spending hours 
> debugging 
> >>>> just the DB connection but todate that is the reality of 
> Java web 
> >>>> app development.  It is why I fear we will all be .Net 
> developers 
> >>>> some day.
> >>>>
> >>>>
> >>>> Example :
> >>>> 
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources
> -howto.html 
> >>>>
> >>>>
> >>>> <CODE>
> >>>>
> >>>> Context initCtx = new InitialContext();
> >>>> Context envCtx = (Context) initCtx.lookup("java:comp/env");
> >>>> DataSource ds = (DataSource)
> >>>>   envCtx.lookup("jdbc/EmployeeDB");
> >>>>
> >>>> Connection conn = ds.getConnection();
> >>>> ... use this connection to access the database ...
> >>>> conn.close();
> >>>>
> >>>> </CODE>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> <WEB.XML>
> >>>>
> >>>> <resource-ref>
> >>>>   <description>
> >>>>     Resource reference to a factory for java.sql.Connection
> >>>>     instances that may be used for talking to a particular
> >>>>     database that is configured in the server.xml file.
> >>>>   </description>
> >>>>   <res-ref-name>
> >>>>     jdbc/EmployeeDB
> >>>>   </res-ref-name>
> >>>>   <res-type>
> >>>>     javax.sql.DataSource
> >>>>   </res-type>
> >>>>   <res-auth>
> >>>>     Container
> >>>>   </res-auth>
> >>>> </resource-ref>
> >>>>
> >>>> </WEB.XML>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> <CONTEXT FILE>
> >>>>
> >>>> <Context>
> >>>>
> >>>>   <Resource     name="jdbc/EmployeeDB"
> >>>>         auth="Container"
> >>>>                 type="javax.sql.DataSource"
> >>>>         username="dbusername"
> >>>>         password="dbpassword"
> >>>>                 driverClassName="org.hsql.jdbcDriver"            >
>>>> url="jdbc:HypersonicSQL:database"
> >>>>         maxActive="8"
> >>>>         maxIdle="4"/>
> >>>>
> >>>> </Context>
> >>>>
> >>>> </CONTEXT FILE>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> Sean Rowe wrote:
> >>>>
> >>>>> Dirk, I'm sorry I didn't see the difference on the page 
> you sent me 
> >>>>> to.  However, if there is a way I can do this without 
> having to use 
> >>>>> jstl, I would really like to know.  I was hoping to put 
> the code in 
> >>>>> a class somewhere that my servlets could use.
> >>>>>
> >>>>> thanks,
> >>>>> sean
> >>>>>
> >>>>> Dirk Weigenand wrote:
> >>>>>
> >>>>>> Sean,
> >>>>>>
> >>>>>>  
> >>>>>>
> >>>>>>> --- Urspr√ľngliche Nachricht ---
> >>>>>>> Von: Sean Rowe <ichabooka@gmail.com>
> >>>>>>> An: Tomcat Users List <tomcat-user@jakarta.apache.org>
> >>>>>>> Betreff: Re: jndi question
> >>>>>>> Datum: Mon, 22 Aug 2005 09:24:10 -0500
> >>>>>>>
> >>>>>>> Thanks for responding Dirk.  I've practically memorized
the 
> >>>>>>> documentation on the link you sent:
> >>>>>>>
> >>>>>>> // Obtain our environment naming context
> >>>>>>> Context initCtx = new InitialContext();
> >>>>>>> Context envCtx = (Context) initCtx.lookup("java:comp/env");
> >>>>>>>
> >>>>>>> // Look up our data source
> >>>>>>> DataSource ds = (DataSource)
> >>>>>>>  envCtx.lookup("jdbc/EmployeeDB");
> >>>>>>>
> >>>>>>> // Allocate and use a connection from the pool
> >>>>>>> Connection conn = ds.getConnection();
> >>>>>>> ... use this connection to access the database ...
> >>>>>>> conn.close();
> >>>>>>>
> >>>>>>> Whenever I try this, here's what I get (which led me 
> to trying it 
> >>>>>>> the way
> >>>>>>> I posted):
> >>>>>>>
> >>>>>>> javax.naming.NameNotFoundException: Name java:comp is 
> not bound 
> >>>>>>> in this
> >>>>>>> Context
> >>>>>>>
> >>>>>>>   
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> No. Did you look at
> >>>>>> 
> http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasourc
> e-examples-howto.html? 
> >>>>>>
> >>>>>>
> >>>>>> I recommend putting the context definition in its own 
> content.xml. On
> >>>>>> redeploying my application tomcat wouldn't find the 
> driver class 
> >>>>>> anymore.
> >>>>>>
> >>>>>> Mind you not the class itself but the definition of 
> what class to 
> >>>>>> load.
> >>>>>>
> >>>>>> This problem was solved by putting the context into 
> context.xml.
> >>>>>>
> >>>>>> regards
> >>>>>>       Dirk
> >>>>>>
> >>>>>>  
> >>>>>>
> >>>>>
> >>>>> 
> ---------------------------------------------------------------------
> >>>>> 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
> >>>>
> >>>
> >>> 
> ---------------------------------------------------------------------
> >>> 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
> >>
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > 
> > 
> 
> 
> -- 
> Brian Cook
> Digital Services Analyst
> Print Time Inc.
> bcook@printtime.com
> 913.345.8900
> 
> 


<FONT SIZE=1 FACE="VERDANA,ARIAL" COLOR=BLUE> 
-------------------------------------------------------
QAS Ltd.
Registered in England: No 2582055
Registered in Australia: No 082 851 474
-------------------------------------------------------
</FONT>


---------------------------------------------------------------------
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