• Post Reply Bookmark Topic Watch Topic
  • New Topic

Testing a servlet - single machine

 
David Garratt
Ranch Hand
Posts: 213
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The war file name is used as the context path so just give the war file a different name.
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 213
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!