File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes JNDI with Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "JNDI with Tomcat" Watch "JNDI with Tomcat" New topic
Author

JNDI with Tomcat

Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Hi,

Can some one please tell me how to config tomcat 5.5 or 6 (with eclipse dynamic web project) for use JNDI look ups.

I have gone throgh some articles but didnt help me.

in this site webpage i have found this,



and in here ,




why type attribute mentioned in two diferent ways..

Thank You.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

The "type" is the classname of the DataSource class that will be instantiated by Tomcat when the resource is created. One is the generic DataSource, one is an Oracle-specific one, and if you'll notice, there's also a factory classname given for that one, meaning that Tomcat will use the factory instead of simply constructing the Oracle DataSource using "newInstance()".

WebSphere also has one or 2 vendor-specific datasource classes, and I'm sure that there a quite a few others out there as well. The ability to specify a custom DataSource type allows you to take advantage of DataSources whose capabilities maximize vendor-specific advantages of a particular DBMS. In particular, you might expect to find both XA and non-XA type datasources available.


Customer surveys are for companies who didn't pay proper attention to begin with.
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Thank You Tim for the answer. by the way if you mind can you specify what steps actually need to configure tomcat successfully with JNDI. I have try several ways but end up with "Cannot get connection: javax.naming.NameNotFoundException: Name xyz is not bound in this Context"

I have found tomcat web site article bit complex and more steps than this article. I hope the latter article also correct right..but it didnt work..but i think that article didnt explain it with eclipse because it says "Add the below webapps/jdbc/META-INF/context.xml file" where i dont find a context.xml file under WebContent/META-INF in eclipse project file structure. can you please answer.

Thank You.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16022
    
  20

Another reason why we're not real excited when people use an IDE to build their projects. An IDE can be a big assist, but it's no substitute for actually knowing what's going on.

Every deployed Tomcat webapp has a context. The context defines the base URL for the app, where to find the application's codebase, and additional defined resources, if/as needed, including the Connection Pool (DataSource) definition. If you don't explictly define a context, one will be created for any WAR found in the TOMCAT_HOME/webapps directory, where the context name will be "warname" and the codeBase will be "TOMCAT_HOME/webapps/warname" or "TOMCAT_HOME/webapps/warname.war", depending on whether or not the WAR is exploded.

You can define a context yourself and put it in one of 3 places.

1. As a file named "context.xml" in the META-INF directory of your WAR.

2. As a file whose extension is ".xml" in the TOMCAT_HOME/conf/Catalina/localhost directory (will override #1).

3. As an XML entry in the TOMCAT_HOME/conf/server.xml file (But please don't do this!).

The full documentation on the format of the Context element and its children is on the Tomcat documentation site. Your DataSource definition would be one of those children.
Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
Thank Tim..i have successfuly did it..
one question please..now what i did was adding <Resource> in context.xml in tomcat (under eclipse) and add <resource-ref> for web..xml in my project....But is there a way to do all settings in server not in project web.xml..i mean the <resource-ref>.. i know its stupid question but there is a project that existing code should not touch..so try to minimize the changes in web.xml..you got the point sir..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNDI with Tomcat