• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

need help to define context for applications stored in webapps subdirectories

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use Tomcat 8 and have some problem to configure contexts for versioned applications.
I have a set of 4 applications: app1, app2, app3 and app4.
I know how to configure Tomcat to have these 4 applications running directly under webapps: I have folders webapps/app1, webapps/app2,... I define app1.xml, app2.xml,... and I place them in \Tomcat 8.0\conf\Catalina\localhost, and everything works fine.
Now I need to manage different versions of these 4 applications.
To do so:
I have organised my folders like this: webapps/v1/app1, webapps/v1/app2,...,webapps/v2/app1, webapps/v2/app2,..
Based on https://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Defining_a_context:
I have defined new context files named v1#app1.xml, v2#app2.xml,..., and I place them in \Tomcat 8.0\conf\Catalina\localhost.
In each of this file, I have set docbase and path, for instance for V1 of app1 I have:
docBase="${catalina.home}/webapps/v1/app1" path="/app1"
When I restart Tomcat, my applications do not start.
I have propably made one or more mistakes, but English is not my native language and Tomcat doc is not very clear, especially for docbase and path.
So if someone can help me to configure this correctly, thanks in advance.
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My recommendation would be that, if you are going to create a non-standard folder structure, to not put the war files under webapps at all. Put them elsewhere, and use the context XML files to map them accordingly.
 
Eric Malalel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't use war files, each app is made of a set of folders and files, and I copy them under the root folder of the app and restart Tomcat, and it works fine.
If there is a "standard" folder structure for applications with different versions, what is this structure and how to configure it?
Or, if I want to use my structure, how do I name the context files, and what do I put in docbase and path parameters?
 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Malalel wrote:I don't use war files, each app is made of a set of folders and files


That doesn't really matter with regards to my reply.

If there is a "standard" folder structure for applications with different versions, what is this structure and how to configure it?


Not of which I am aware.

Or, if I want to use my structure, how do I name the context files, and what do I put in docbase and path parameters?


The new location of the folders. It defaults to webapps, but you'll need to set it to your custom location(s).

I haven't done this in a long time, but I'll scout around to see if I have an old example login around.
 
Eric Malalel
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I hope you will find something. I have been googling the whole day and found nothing so far.
 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, here's a simple example of a context XML where I set up a custom folder (one not in Tomcat's folder structure) locally on my Mac:


The app context is /testbed and the context file is named testbed.xml, and is placed in Tomcat's conf/Catalina/localhost folder.

The WEB-INF folder of the application is in the /Users/bear/Dropbox/Development/projects/testbed/web folder.

It should be easy to figure out a folder structure that suits your needs and just make sure that the docBase values in the context descriptors match that structure.
 
Saloon Keeper
Posts: 24310
167
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
It should be easy to figure out a folder structure that suits your needs and just make sure that the docBase values in the context descriptors match that structure.



GOTCHA!


If you setup a Context XML file and drop it in conf/Catalina/localhost, the webapp's context path will NOT be the value indicated in the context file. It will be the NAME of the context file

That is, file "foobar.xml" with a Content element of


Will be served at context "/foobar" and not context "/testbed". It's another one of Tomcat's little quirks, like not updating a webapp if you replace a war file but there's already an older exploded WAR of the same name. Fortunately, the docBase attribute is honored and I use that feature extensively. But the path attribute isn't, so beware!



There is no "standard directory structure" in Tomcat. Tomcat webapps are ALWAYS WARs, whether actual WAR files, or their exploded counterparts. You cannot just go dropping files willy-nillly into Tomcat. So the "standard directory" structure is the WAR format as specified in the J2EE spec and Tomcat does not diverge from it.

I am not clear as to whether you truly mean "version" of a webapp or "instance". In Tomcat, there is a many-to-one relationship between contexts and WARs. In other words, I can use /app1, /app2, /app3 and /app4 as contexts (by defining an app1.xml, app2.xml, etc.) and they would all be able to be independent webapp instances based on (and sharing) "mywebapp.war".

Actual webapp versioning is a rather ugly thing that appears to be based on a kludge wherein you tack on a "##"version to the WAR name, then map it to a context or contexts. It strikes me as possibly useful when doing version migrations on a "hot" server, where existing users continue running the older version, but as new users connect, they would be assigned to the newer version until finally the older-version users all signed off and you could safely remove the old WAR. For anything else it seems more trouble than it's worth.
 
Bear Bibeault
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:If you setup a Context XML file and drop it in conf/Catalina/localhost, the webapp's context path will NOT be the value indicated in the context file. It will be the NAME of the context file


Yeah, I should have mentioned that -- always name the file the same as the path so that there's no ambiguity.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic