• 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

Testing a servlet - single machine

 
Ranch Hand
Posts: 333
1
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At the moment I develop my servlet in Eclipse and create the .war file with a ant script. All fine and works without issue. If I want to have 2 copies of the application (live and test) on the same server is it best practice to have to instances of Apache Tomcat running or is there some way to change the application name during the build process so that when it's dropped into the webapps directory it will not conflict with the live copy.
 
Sheriff
Posts: 67746
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
The war file name is used as the context path so just give the war file a different name.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It probably would have been better to ask this question in the Tomcat forum, as practices vary depending on what brand of server you are using.

I would generally run 2 separate Tomcats but not because the "same" WAR is involved. Instead it's because one of them is a test service and the other is production. I prefer to run a separate production server so that it's insulated from the somewhat more unstable environment that test servers typically endure. Also, for several versions of Tomcat/JDK, repeatedly deploying a WAR risked encountering the dreaded "out of PermGen space" error, and test systems tend to re-deploy a lot. Restarting a test server when that happens rarely causes the excitement that restarting a production server does.



You can deploy the same WAR multiple times and even with different configurations (for example, using test and production databases) in the same server. That's because when you deploy a webapp, there are 2 deployment descriptors. One is the server-independent Deployment Descriptor, better known as WEB-INF/web.xml.

For Tomcat, the other (server-dependent) Deployment Descriptor is represented by the Tomcat Context element. You can define this element explicitly and place in in the WAR's META-INF/context.xml file, in the TOMCAT_HOME/conf/Catalina/localhost/xxx.xml file, or omit it and drop the WAR (either as a WAR file or unzipped (exploded) directory in the TOMCAT_HOME/webapps directory. Or apply variations on this depending on how you set up server.xml (which can be, but should NOT be another place you can put a Context).

The Context element has an attribute that would appear to be the context path that the webapp instance should show up under. Thus, the same WAR can be run as 2 independent webapps by simply defining 2 separate Contexts. Note, however, that I said "should". Some versions of Tomcat ignore this attribute and use the name of the Context file (minus the ".xml" suffix) as the context pathname. If you drop a WAR in TOMCAT_HOME/webapps and don't use a Context file, then the Context path will the the same as the name of the WAR file (minus the .war suffix) or WAR directory.

The full details of this mechanism, including what happens if you have multiple possible Context definitions is well-documented at the Tomcat site in the documentation pages for whichever version of Tomcat interests you.
 
Bear Bibeault
Sheriff
Posts: 67746
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
I"ve added this post to the Tomcat forum.

And I agree with everything Tim wrote, but to get started, it's easier to run a single instance of Tomcat to get feet wet.
 
David Garratt
Ranch Hand
Posts: 333
1
Mac Eclipse IDE Safari
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for both replies. At the moment I don't have control over the number of physical servers as that's a customer decision. I will have to read up a little more.

Feedback most appreciated.

Dave
 
Tim Holloway
Saloon Keeper
Posts: 27762
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

David Garratt wrote: At the moment I don't have control over the number of physical servers as that's a customer decision.

Dave



There are physical servers (boxes), virtual servers (VMs) and Tomcat servers (Server instances). Not counting Containers and other variations.

You can have multiple instances of the Tomcat server within a server machine (box or VM). All that's required is for each Tomcat instance to own a unique set of ports. Because TCP/IP doesn't allow more than one program to own (listen on) any given port number.
 
reply
    Bookmark Topic Watch Topic
  • New Topic