You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mindaugas Žakšauskas <mi...@gmail.com> on 2008/02/18 11:40:25 UTC

JNDI question/problem

Hi,

I'm using Tomcat v5.5.25 with two webbaps deployed as plain files (not
wars). Both of them use JNDI and do some initial binding upon webapp
(context) startup.
The "startup" event is determined by implementing a listener
(javax.servlet.ServletContextListener's contextInitialized method) and
placing it in WEB-INF/web.xml.

Now, there are (at least) two ways of defining/configuring webapp contexts:

1) by having both webapps defined in conf/server.xml, e.g.:

<Server ...>
  <GlobalNamingResources>
     <Resource name="foobar" auth="Container" type="java.util.HashMap"
factory="org.apache.naming.factory.BeanFactory"/>
  </GlobalNamingResources>

  <Service ...>
     <Connector.../>

     <Context path="" docBase="/path/to/my/webapp1">
        <ResourceLink global="foobar" name="local_foo" type="java.util.Map"/>
     </Context>
     <Context path="" docBase="/path/to/my/webapp2">
        <ResourceLink global="foobar" name="local_bar" type="java.util.Map"/>
     </Context>

  </Service>
</Server>

2) By having Context part defined separately, e.g. sitting in
conf/Catalina/localhost/webapp1.xml and
conf/Catalina/localhost/webapp2.xml

Now the difference between the two is that for the (1) case linked
JNDI resource ("java:comp/env/local_bar") is not available upon
startup - I'm getting "javax.naming.NameNotFoundException: Name
local_bar is not bound in this Context". Although when the config sits
separately from server.xml, as in case (2), everything works just fine
and JNDI contains all configured bindings/resource links.

The question is, is this a normal behavior or something that should be
addressed/fixed? Also, is there any bit of JNDI spec which would speak
of JNDI availability upon server/webapp startup?

I would prefer to use the (1) approach as in some cases I need to
specify the order of which webapp starts first while this is not
possible using (2).

Thanks indeed anyone for any ideas, really much appreciated.

Regards,
Mindaugas

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JNDI question/problem

Posted by Mindaugas Žakšauskas <mi...@gmail.com>.
Hi Charles,

...and thanks for your reply.

> You appear to be trying to define two default contexts (path=""), which is obviously incorrect <..>

Just to be more precise and address your point:

- I am running Tomcat without its default apps (manager, root), only
my own apps are set up;
- when I define both contexts in server.xml, I obviously put different
path="..." on contexts, the given example was for illustration
purposes only. Sorry for the confusion.

Just to repeat myself, I only have to put Context entries inside
server.xml to be able to control the startup order of the webapps. If
you could suggest me how would I achieve setting the startup order by
having separate files, I would be able to get rid of at least two
problems in my life. Thanks again for your effort & time.

Regards,
Mindaugas

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: JNDI question/problem

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Mindaugas Žakšauskas [mailto:mindas@gmail.com] 
> Subject: JNDI question/problem
> 
>   <Service ...>
>      <Connector.../>
> 
>      <Context path="" docBase="/path/to/my/webapp1">
>         <ResourceLink global="foobar" name="local_foo" 
> type="java.util.Map"/>
>      </Context>
>      <Context path="" docBase="/path/to/my/webapp2">
>         <ResourceLink global="foobar" name="local_bar" 
> type="java.util.Map"/>
>      </Context>
> 
>   </Service>
> </Server>

You appear to be trying to define two default contexts (path=""), which is obviously incorrect, and likely conflict with Tomcat's existing default app in [appBase]/ROOT.  Since you shouldn't be putting <Context> elements inside server.xml and the resource reference works when you place the <Context> elements in valid locations, your question is somewhat moot.

Note that when <Context> elements are not in server.xml, the path attribute must not be used (it's usually ignored, but can cause problems).

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org