🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.database
Article #425

Re: JNDI Connection Problem

#425
From: Paul Furbacher [TeamB]
Date: Mon, 05 Dec 2005 20:13
130 lines
6003 bytes
Tom wrote:

> Thanks for input - still having trouble though:
> 
> I'm not seeing any context files in webapp/Tomcat/conf (other than the 
> one the context.xml file I placed there as a troubleshooting step.)  

Sorry, I realize now that for Tomcat 5.5 in JBuilder
the context is in the server8080.xml

   <project dir>/Tomcat/webapps/

That's where you should add your Resource definition.

(I must have been flipping back and forth between
TC 4.1.x and TC 5.5.x examples and gotten confused
as to which I was looking at.)

> Do I need to manually add the .xml file in this directory, 

No, start your Web app, and JBuilder will create it.
Of course, your data access will fail, but the object
of doing this is just to have JBuilder create the file.
Before you shut down Tomcat, make a copy of that server8080.xml
file.  Shut down the server.  Do the editing as described
in the archives.

> <Host appBase="C:\Documents and 
> Settings\user\jbproject\webapp\Tomcat\webapps" ...

> <Context docBase="C:\Documents and 
> Settings\user\jbproject\webapp\webmodule" ....

Okay, if were able to do a search of the archives
to find the most often diagnosed problem it would
be this: Tomcat path spaces.

Tomcat has never liked spaces in pathnames, so I don't
even tempt fate by putting projects in the suggested
home directory on Windows.

On Windows, redefine your default project to start
in a path which has no spaces in it. I do something
like

   d:/projects/

Then, move your current project to this projects dir
and make the appropriate changes in the Project Properties,
etc. config dialogs.



> <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource"
>                maxActive="10" maxIdle="30" maxWait="10000"
>                username="root" password="xxxx" 
> driverClassName="com.mysql.jdbc.Driver"
>                url="jdbc:mysql://localhost:3306/test"/>

> ------  .java code snippet -----------------
> ctx = new InitialContext();
> pool = (DataSource)ctx.lookup("java:comp/env/jdbc/mysql");
> 
> This is the code that is failing
>  
> ---  user/jbproject/sidehire/webmodule/WEB-INF/web.xml ---------------
 > [...]
>   <resource-ref>
>     <description>MySQL DB Connection</description>
>     <res-ref-name>jdbc/mysql</res-ref-name>
>     <res-type>javax.sql.DataSource</res-type>
>     <res-auth>Container</res-auth>
>   </resource-ref>
> [...]
> --------------------------------
> 
> Thanks for any help.  I did find this solution approach (see below) 
> posted on the board - I tried to emulate this approach without success 
> (note this solution did not seem to require use of any context.xml files 
> - they only placed their resource information in the server8080.xml file.)
> 
> "SOLVED: Datasource in JBuilder 2005 (Configuring the Web Module)
> ... by putting the <Resource> in the server8080.xml and following the 
> rest of theinformation in your inline post, I *FINALLY* am able to use a 
> datasource from my ..."

This should work.  I just tested this with the Spring JPetstore
where I added a JNDI datasource to the server8080.xml file,
and added a JndiObjectFactoryBean in the app context file.
Spring is able to look up the resource, so that means that
putting the resource definition in the server8080.xml file
does indeed work.  Otherwise, Spring wouldn't be able to
instantiate the bean and would throw visible exceptions.

> Finally, I assume you were using Tomcat 5.5?  For this Tomcat version, 
> Tomcat expects to read the JNDI context information from the 
> /META-INF/context.xml file, not the server.xml file - so I assume 
> Jbuilder is taking care of this behind the scenes.

Is this completely true?  My reading of the Tomcat 5.5 docs
suggests that there are three places where this type of context
definition might be placed (see Tomcat 5.5 docs at
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html).
It is advised, but not prohibited, that you not place the
context info in the server.xml file since the latter file
cannot be reloaded.  However, for development in JBuilder,
it seems to me rare that you'd be trying to reload server8080.xml.
I haven't played with the server8080.xml definition since the
first time I set it up.  What I do fiddle with are the Spring
app context files, and rarely the web.xml file (mostly via
the a DD Editor in JBuilder, not directly).

So, just add your resource definition to the server8080.xml
file as described in the archives.


-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://info.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Technical Details
Message-ID: <43949f45$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <42c3a0a6$1@newsgroups.borland.com> <42c879ec$1@newsgroups.borland.com> <43913a32$1@newsgroups.borland.com> <43913ece$1@newsgroups.borland.com> <43922281$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 1073da,2417608254d405db
X-Google-Attributes: gid1073da,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Mon, 05 Dec 2005 15:13:49 -0500
From: "Paul Furbacher [TeamB]" <pfurbacher@mac.com>
Organization: Reverse Alchemy, Inc.
User-Agent: Mozilla Thunderbird 1.0.6 (Macintosh/20050716)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.database
Subject: Re: JNDI Connection Problem
References: <42c3a0a6$1@newsgroups.borland.com> <42c879ec$1@newsgroups.borland.com> <43913a32$1@newsgroups.borland.com> <43913ece$1@newsgroups.borland.com> <43922281$1@newsgroups.borland.com>
In-Reply-To: <43922281$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.142.194.228
Message-ID: <43949f45$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1133813573 69.142.194.228 (5 Dec 2005 12:12:53 -0700)
Lines: 130
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail