• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

i am a tomcat idiot. Need help using context roots

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've never been able to figure out how to properly use context paths with tomcat. It's really frustrating because reading the docs it seems like it's something that should be very easy, and I know I am not that dumb!!

In the past how I got around not getting them to work was to name my wars with a #.. so deploying first#second#third.war in webapps got me a url of http://www.domain.com/first/second/third/index.jsp (for that particular application).

Now I would like to figure out how to get a similar result using context paths.

I've created appname.xml in $catalina_home/conf/Catalina/localhost/infocenter.xml and tried starting tomcat
<Context path="/blah/infocenter" docBase="/usr/local/tomcat/current/server/webapps/infocenter" debug="0" privileged="false">

</Context>

based on what I've read, this should result in a url of http://www.domain.com:8080/blah/infocenter/index.jsp (again the webapp im depoying has index.jsp as it's resource)... but this did not work.

I've tried about 100 different things and I just can't figure it out.

Also when using context roots, I assume you have to explode the war yourself and it won't autodeploy?

Back to banging my head on the desk for now...

 
Derek Murphy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I actually might have just figured it out, although I'm not completely confident on how it's working, so if someone could explain, that would be awesome

I have an infocenter webapp (eclipse based documentation) deployed at $catalina_home/server/webapps/infocenter/ (server/webapps/infocenter i created)

I created $catalina_home/conf/Catalina/localhost/blah#infocenter.xml

<Context path="/blah/infocenter" docBase="/usr/local/tomcat/current/server/webapps/infocenter" debug="0" privileged="false">

</Context>

I then unjar'ed the war file manually in $catalina_home/server/webapps/infocenter

This seemed to make everything work.
My question is... how can I get tomcat to auto-deploy stuff that lives in $catalina_home/server/webapps/ just like the normal webapps?

I think the big thing I was missing all along is the # based naming of the context.xml files. I had never realized those needed to include # signs for multi level naming conventions. I always thought that's what the context path specified.

Which I guess brings me to my next question... what is the Context path actually doing if it's not telling tomcat what the URI is? It seems like the naming of the xml (blah#infocenter) in this case is what tells tomcat what the URI is going to be.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can actually deploy a context.xml file (which contains the <Context> element) as part of the war file; see http://tomcat.apache.org/tomcat-6.0-doc/config/context.html - the paragraph after the one where it talks about the "#" stuff. Is that what you're asking?
 
Derek Murphy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nope. Not deploying context.xml within the war. The war is being provided to me.

I think I'm slowly figuring this stuff out
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, it's early and my vision is blurry, but I think this may help:

1. Tomcat will automatically scan the TOMCAT_HOME/webapps directory at startup (I use "TOMCAT_HOME" because I can never keep CATALINA_HOME and CATALINA_BASE straight and usually they're the same thing). Any exploded WAR directories are scanned for the presence of a META-INF/context.xml file. If one is found, it will be used to build a Tomcat webapp context - that is, to deploy the exploded WAR. If no such file is found, Tomcat will fake it and assign a context name that's the same as the war directory name.

2. Tomcat will also look for unexploded (a/k/a "real") WARs in the webapps directory. WAR files, in other words. IIF there is no exploded WAR with the same name as the WAR file (minus the ".war extension), then Tomcat will unzip (explode) the WAR file and do the Step 1 process to it. If you update the WAR file, tough. The exploded version takes precedence, even when it's older than the WAR file.

Note that Tomcat doesn't actually HAVE to ever explode WARs. That's just the default behavior.

3. Actually, more like "0". The TOMCAT_HOME/conf/Catalina/localhost directory will be scanned for XML files containing Tomcat Context definitions. These definitions take precedence over webapps in the TOMCAT_HOME/webapps directory. The Context will normally define the URL context name and the docBase for the webapp. The docBase can be either a WAR file or an exploded WAR. I don't actually recommend pointing the docBase to anywhere in Tomcat except for immediately under the TOMCAT_HOME/webapps directory. On a *n*x OS, I used to keep them in "/opt/com/mycompany", although these days, I might use the "/srv" directory as a basis instead.

 
Derek Murphy
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,
Thanks for the responses!

This clarifies things a bit in terms of how the context stuff works. I finally got the context path's working so that's grand.. although the application is misbehaving.. such as life.

Offtopic (sort of) question, but kind of related..

If I compile an apache httpd module on a development server, can I simply move the compiled modules (so files) to my production server, without the need to install any of the supporting libraries etc.. that I needed when I compiled it?
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Libraries come in 2 flavors: development libraries and runtime libraries. Well, I could probably come up with more flavors, but for this discussion they'll do. Besides, the paradigm of the Age is black-and-white Absolutes.

The development libraries aren't needed on the production machine. The runtime libraries are. So you'll need compatible versions of those libraries on the production machine and they'll have to be in the httpd server's load library path. At that point, things get a little complicated and very OS-specific, so I'd have to refer you to an OS-specific forum such as the Linux/Unix forum.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic