Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing GlobalNamingResources values through JDNI

 
John Farrel
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are repeating yourself on directory levels. Try this:

 
John Farrel
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Also tried this with no success:



 
John Farrel
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic