JNDI Question Regarding Tomcat 5.5
This is my first java app, so please bare with me.
I've developed a java application using NetBeans 5.5 and have incorporated JNDI to acquire my connection information I have both my Context.xml and my web.xml working properly in NetBeans. My question is what do I have to do in order to have Tomcat handle the serving up of my connection information via JNDI? This way if the connectoin information changes I only need to edit file with TomCat for my app to work properly. What .xml files need to be edited in Tomcat? TomCat is bundled with NetBeans version 5.5.17. Eventually I would like to deploy my java app to use a stand alone version of TomCat. Any advice regarding this is greatly appraciated.
Thanks.
[730 byte] By [
FAT-BOYa] at [2007-11-26 16:52:57]

# 2
The .xml file you have to edit is server.xml (or the file you set as the server configuration of tomcat). The file is located in /conf folder of tomcat靤 installation directory.
Here is a snippet of configuration for the server.xml defining a webapp called "myApp":
<Context path="/myApp" reloadable="true" docBase="D:\development\workspace\myApp\WebApp" workDir="D:\development\workspace\myApp\WorkDir">
<Resource name="jdbc/AppDb" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/AppDb">
<parameter><name>username</name><value>dbuser</value></parameter>
<parameter><name>password</name><value>dbpass</value></parameter>
<parameter><name>driverClassName</name>
<value>org.hsql.jdbcDriver</value></parameter>
<parameter><name>url</name>
<value>jdbc:HypersonicSQL:database</value></parameter>
</ResourceParams>
</context>
This configuration create a DataSource called jdbc/AppDb. To use it in your app you must add to your web.xml file a resource reference like this:
<resource-ref>
<description>AppDb DataSource</description>
<res-ref-name>jdbc/AppDb</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
And within you code you can get a DataSource reference by JNDI:
InitialContext ic = new InitialContext();
String jdbcDS = "java:comp/env/jdbc/AppDb";
DataSource ds = (DataSource)ic.lookup(jdbcDS);
Note that Tomcat 5.0.x and Tomcat 5.5.x have some little differences defining resources in xml sintax.
# 4
It's a portion of server.xml file used by tomcat. If you want to deploy a web application with some custom configuration you could create a new web context using the line show above.
It specifies that there is a web application which base directory is in D:\development\workspace\myApp\WebApp and uses D:\development\workspace\myApp\WorkDir as work directory and the web context is myApp.
# 5
I used the exmple above to try and get My app created in NetBeans to work on a TomCat server, but it's not working do I need this context line? Basically I need my .WAR file to locate on TomCat the conneciton information. I also edited the web.xml file in my app as you instructed above, but the ap is erroring out, whay am I missing, rather what else can I do to get this to work?
thanks.
JTRa at 2007-7-8 23:20:39 >
