my dog learned polymorphism*
The moose likes Tomcat and the fly likes Error confguring multiple contexts/data sources in Tomcat 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Error confguring multiple contexts/data sources in Tomcat 5" Watch "Error confguring multiple contexts/data sources in Tomcat 5" New topic
Author

Error confguring multiple contexts/data sources in Tomcat 5

Neelesh A Korade
Greenhorn

Joined: Jun 07, 2007
Posts: 26
Hello

I am using Tomcat 5.5.27. I have two web applications- App1 and App2. Below are some details-

  • App1 Data Source JNDI name - jdbc/DW_Pool
  • App1 web context name - tdwebapps
  • App2 Data Source JNDI name - jdbc/SQLPool_DW
  • App2 web context name - tdreports


  • My context.xml and server.xml are given at the end of this post.

    When I start Tomcat with these configurations and try to access my application, I see the following error in the log-

    Aug 25, 2009 10:14:12 PM org.eclipse.birt.report.data.oda.jdbc.JndiDataSource getConnection
    INFO: javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
    Aug 25, 2009 10:14:12 PM org.eclipse.birt.data.engine.odaconsumer.ConnectionManager openConnection
    SEVERE: Cannot open connection.


    My questions are-
    1) Where am I going wrong? How to get rid of this exception?
    2) I referred to the Tomcat config documentation given at- http://tomcat.apache.org/tomcat-5.5-doc/config/index.html
    However, I have not been able to understand the significance of Context.xml file exactly. If we can configure contrexts, resources etc. in server.xml file, what purpose does the Context.xml file serve?

    My Context.xml file-


    My server.xml file-


    Tim Holloway
    Saloon Keeper

    Joined: Jun 25, 2001
    Posts: 16019
        
      20

    Context.xml allows you to define the context for a single webapp in a discrete file. Effectively, all the context files are merged into server.xml. But by physically separating them, you can redeploy a single webapp without changing server.xml itself, which would require restarting the entire server.

    As a fat-fingered user type, there's another benefit. If you damage server.xml, the entire Tomcat server may become unusable. So by editing only a single context file, you only put that particular webapp at risk.

    Use of a separate context file became the preferred way to define a webapp context starting in Tomcat 4 and continuing to the present day. You can also include a copy of the context as META-INF/context.xml (I may have that mis-capitalized) in your WAR, which allows you to make "drag and drop" WARs complete with JNDI and other container definitions that normally would be external to the war.


    Customer surveys are for companies who didn't pay proper attention to begin with.
    Neelesh A Korade
    Greenhorn

    Joined: Jun 07, 2007
    Posts: 26
    Thank you Tim. That was helpful.

    Could someone help me out with the data source lookup exception I am seeing?
    Tim Holloway
    Saloon Keeper

    Joined: Jun 25, 2001
    Posts: 16019
        
      20

    I didn't see anything obvious, although if you define it twice (once in context and once globally), that might cause problems.

    The only other thing is that you also have to define the resource in web.xml, if I'm not mistaken:

     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Error confguring multiple contexts/data sources in Tomcat 5