Hosting 2 versions of the same Java website in tomact

I have a website set up in a unix server.

I work in a team with two more developers who also work on the website.

The requirement is running two or more versions of the same site from two different directories in the same unix server.This is because two developers will be working on the same feature on the same files and having differnt versions of the same site will prevent each other from modifying the other developrs files.

Now I have copied the entire website webapps contents into another directory in the same server.

I have tomcat which was previously installed which points to the original webapps directory.

Now what do I need to do in order to host the new site which I have copied into a new directory.

What are the viable options here?


I suggest opening bin/catalina.sh in a text editor and start reading downward from this point:

# -----------------------------------------------------------------------------
# Control Script for the CATALINA Server
#
# Environment Variable Prerequisites
#
#   Do not set the variables in this script. Instead put them into a script
#   setenv.sh in CATALINA_BASE/bin to keep your customizations separate.

bin/setenv.sh does not exist by default, but it's a real gem: any variables or scriptlets that you place in such a file get sourced by bin/catalina.sh, which in turn gets invoked whenever bin/startup.sh and bin/shutdown.sh get invoked.

  • Continue to read downward from that point and note the various variables and what they do. Some of them may be familiar to you already, like JAVA_HOME. Others might not be, like CATALINA_OPTS, which should be preferred over JAVA_OPTS where possible.
  • Examine bin/startup.sh and bin/shutdown.sh carefully, looking for customizations: none of the variables explained in the bin/catalina.sh documentation should be defined. Administrators and developers who don't know of bin/setenv.sh have a tendency to modify the startup and shutdown scripts directly, which is a bad practice. Move these customizations to bin/setenv.sh so that you can keep better track of the differences between your two Tomcat containers.
  • Use JAVA_HOME to specify the path to the different installations of Java. Tomcat will execute $JAVA_HOME/bin/java, not the version of java that happens to be in your PATH variable. (unless JRE_HOME exists, the documentation I've directed you to read explains the difference) If each Tomcat needs to use a different version of Java, then they should have different JAVA_HOME paths. If they should use the same version of Java, then the variable should be the same for both.
  • Adjust conf/server.xml and change the ports that Tomcat is listening on. All instances of the word port that are not inside of a comment block (<!-- -->) must be adjusted or there will be port conflicts.
  • If you have a requirement that both of these Tomcats must be behind a single port, you will either need a load balancer in front of them, or a webserver that proxies the traffic. The webserver can run on the same machine, you would proxy to localhost (127.0.0.1) in such case. Based on the requested URI, have the load balancer or web server route the traffic to the appropriate Tomcat.