GeeCON Prague 2014*
The moose likes Tomcat and the fly likes Accessing GlobalNamingResources values through JDNI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Bookmark "Accessing GlobalNamingResources values through JDNI" Watch "Accessing GlobalNamingResources values through JDNI" New topic
Author

Accessing GlobalNamingResources values through JDNI

John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 84



I am trying to access this value, set in server.xml, at runtime.

Somehow I am meant to use something like:



but I always get an exception.

Can anyone help?

John
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16094
    
  21

You are repeating yourself on directory levels. Try this:


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

Joined: May 24, 2010
Posts: 84


I did as you suggested and still got this exception:

"Name [configDirectory] is not bound in this Context. Unable to find [configDirectory]."

I am debugging tomcat through netbeans... might there be an issue there?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16094
    
  21

John Farrel wrote:
I am debugging tomcat through netbeans... might there be an issue there?


There shouldn't. There something fundamentally wrong with any webapp that care what IDE you're using.

I think actually you are probably missing the web.xml definition of this resource that gets paired to the Tomcat context override.
John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 84

Also tried this with no success:



John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 84
Tim Holloway wrote:
John Farrel wrote:
I am debugging tomcat through netbeans... might there be an issue there?


There shouldn't. There something fundamentally wrong with any webapp that care what IDE you're using.

I think actually you are probably missing the web.xml definition of this resource that gets paired to the Tomcat context override.


I see, I think.

I can't access the global settings unless I also map them in web.xml to the local context?

I am trying to avoid that... is there any other way to do this?

John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 84
Maybe I should explain what I'm trying to do.

We run multiple webapps on the one tomcat instance. They are all running the same war (renamed), but each context has it's own .ini settings.

I am going to set the global value to a directory, then pick up the .ini file for the context based on the context name.

The contexts running on any one tomcat instance may change over time, so I don't want to have to keep creating/editing other .xml files for this to work.

My fallback is that I get the directory path from an environment variable instead.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16094
    
  21

I can't recommend environment variables for webapps. They're not a good fit, as they're targeting the entire JVM, not the app.

What you are proposing is nothing I haven't done. However, I never did see what you did to WEB-INF/web.xml to define the JNDI variable's prototype/default.
K. Gil
Ranch Hand

Joined: Apr 29, 2011
Posts: 75

I can't access the global settings unless I also map them in web.xml to the local context?
I am trying to avoid that... is there any other way to do this?


If a resource has been defined in a Context element it is not necessary for that resource to be defined in /WEB-INF/web.xml
If it's defined outside Context element, web.xml entry is required, otherwise your app can't see this resource.

John Farrel
Ranch Hand

Joined: May 24, 2010
Posts: 84
K. Gil wrote:
I can't access the global settings unless I also map them in web.xml to the local context?
I am trying to avoid that... is there any other way to do this?


If a resource has been defined in a Context element it is not necessary for that resource to be defined in /WEB-INF/web.xml
If it's defined outside Context element, web.xml entry is required, otherwise your app can't see this resource.



So, to be clear, there's no way to define a resource in server.xml that is available to all contexts without also defining a link to that resource in each web.xml then?
Seems like pointless double handling to me... but if that's the way it is so be it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing GlobalNamingResources values through JDNI