On Thu, Aug 21, 2014 at 8:11 AM, André Warnier <a...@ice-sa.com> wrote:
> >>>>>>>> The subject says "on the same pc". Now that is not a guarantee that >>> we are talking about Windows here, but at least a strong >>> suspicion. In such a case, there is the question of whether this >>> relates to running Tomcat as a Windows Service, or in a command >>> window, or both. So this may all be a bit more complicated than >>> meets the eye. >>> >> >> While that may be true, that's an implementation detail (e.g. Windows >> Service versus Debian Linux package-maintained service, etc.). The >> point is that Tomcat can in fat be run side-by-side on the same >> machine: the mechanisms exist to do so... you may have to work a bit >> to get it working with your deployment strategy. >> >> > I understand that. What I meant is that the OP may need some guidance as > to what parameters / environment variables / system variables etc.. are > used when running as a Windows Service, or in a Windows command window e.g. > For example, if running Tomcat in a command window, then the file > bin/setenv.bat would be run if it exists. But when running as a Service, > it won't. > (Neither do I know how you would have to set CATALINA_HOME e.g., if you > have 2 different Tomcats running as Services; neither in fact whether it > matters in that case). > > André and Chris, You provided some really helpful and insightful information. I wanted to go back to the OP's original post: "For development purpose, I wonder if I could install and run Tomcat 6 and 7 the same time on my same development box?" NEWITUS, I wanted to provide a very pragmatic and "easy" approach to the problem you described, so here are my assumptions, and suggested steps: Assumptions: - I need to test and develop my application on both Tomcat6, Tomcat7 (and Tomcat8) platform. - I am developing on Windows platform (for Linux/Mac changes are minimal, please request again - and I will update the scripts). - I need an easy way to install/uninstall Tomcat6,7,8... - I am not considering Tomcat as a Windows service, as I want to be able to easily move things around to other Windows/Linux/Mac machines and setups. - I have multiple JDKs installed on my system, and I want to test with all of them. Steps: 1. Download ZIP binaries from tomcat.apache.org, for various Tomcat release versions, e.g. http://tomcat.apache.org/download-60.cgi http://tomcat.apache.org/download-70.cgi http://tomcat.apache.org/download-80.cgi Pick Core ZIP version, e.g. apache-tomcat-6.0.41.zip apache-tomcat-7.0.55.zip apache-tomcat-8.0.9.zip (Linux/Mac users can also use ZIP version and unzip utility) 2. Unzip each ZIP version file to your dev environment folder, e.g. C:\dev You will end up with the following directories: C:\dev\apache-tomcat-6.0.41 C:\dev\apache-tomcat-7.0.55 C:\dev\apache-tomcat-8.0.9 3. Let's assume you have three JDKs installed, e.g. C:\Program Files\jdk1.6.0_45 C:\Program Files\jdk1.7.0_67 C:\Program Files\jdk1.8.0_20 Obviously, the latest one will be in the PATH (on Windows) and we will customize which one we want to use for any of the environment variations, e.g. Tomca6 + JDK6 Tomcat6 + JDK7 Tomcat6 + JDK8 Tomcat7 + JDK6 Tomcat7 + JDK7 Tomcat7 + JDK8 Tomcat8 + JDK7 Tomcat8 + JDK8 (Tomcat8 requires JDK7 and above) For various Mac and Linux flavours, there are ways you can setup JDK binaries to be on your path by default. 4. In order to run these three Tomcat instances at the same time, you will need to update the port numbers, as you can have only one program bind to a single IP+PORT combination. Out of the box - all three Tomcat versions didn't change default port assignments. They are all defined in the TOMCAT_VERSION/conf/server.xml file, e.g. C:\dev\apache-tomcat-6.0.41\conf\server.xml C:\dev\apache-tomcat-7.0.55\conf\server.xml C:\dev\apache-tomcat-8.0.9\conf\server.xml The default port numbers are as follows, in order of appearance in the server.xml 8005 - shutdown port - appears at the top of the file in <Server> element (Line 22 in all three server.xml files) 8080 - appserving port - further down under <Connector> element (Line 68-70 in all three server.xml files) 8009 - ajp port - further down under next <Connector> element (Line 90-92 in all three server.xml files) Also, you will see references to port 8443 which is disabled (commented out) by default on all three server.xml files (Tomcat 6,7,8). You can safely ignore that port for now, unless you want to configure secure (SSL) connector as well, in that case you will need to update all references (redirect attributes). I suggest you don't touch that for now. 5. Given the default (out-of-box) port assignment, you might want to define your port assignment rules, e.g. default-out-of-box: 8005, 8009, 8080 Tomcat6: 8006, 8010, 8081 Tomcat7: 8007, 8011, 8082 Tomcat8: 8008, 8012, 8083 Update all three server.xml files accordingly. 6. Now, we just need to take care of the JAVA_HOME and Java binaries you would like to use to run these Tomcat instances. It will be the easiest if you run the same JDK for all three instances, as there is nothing else to setup, just run your Tomcat instances, e.g. C:\dev\apache-tomcat-6.0.41\bin\startup.bat C:\dev\apache-tomcat-7.0.55\bin\startup.bat C:\dev\apache-tomcat-8.0.9\bin\startup.bat 7. Let's create new startup scripts for all various Tomcat/JDK versions, e.g. C:\dev\scripts\startTomcat6_jdk6.bat C:\dev\scripts\startTomcat6_jdk7.bat C:\dev\scripts\startTomcat6_jdk8.bat C:\dev\scripts\startTomcat7_jdk6.bat C:\dev\scripts\startTomcat7_jdk7.bat C:\dev\scripts\startTomcat7_jdk8.bat C:\dev\scripts\startTomcat8_jdk7.bat C:\dev\scripts\startTomcat8_jdk8.bat Here are some examples: ---startTomcat6_jdk6.bat--- @echo off set "CATALINA_HOME=C:\dev\apache-tomcat-6.0.41" set "TITLE=Tomcat 6.0.41 on JDK 1.6.0_45" set "JAVA_HOME=C:\Program Files\jdk1.6.0_45" %CATALINA_HOME%\bin\startup.bat --------------------------- ---startTomcat6_jdk7.bat--- @echo off set "CATALINA_HOME=C:\dev\apache-tomcat-6.0.41" set "TITLE=Tomcat 6.0.41 on JDK 1.7.0_67" set "JAVA_HOME=C:\Program Files\jdk1.7.0_67" %CATALINA_HOME%\bin\startup.bat --------------------------- ---startTomcat6_jdk8.bat--- @echo off set "CATALINA_HOME=C:\dev\apache-tomcat-6.0.41" set "TITLE=Tomcat 6.0.41 on JDK 1.8.0_20" set "JAVA_HOME=C:\Program Files\jdk1.8.0_20" %CATALINA_HOME%\bin\startup.bat --------------------------- ---startTomcat7_jdk6.bat--- @echo off set "CATALINA_HOME=C:\dev\apache-tomcat-7.0.55" set "TITLE=Tomcat 7.0.55 on JDK 1.6.0_45" set "JAVA_HOME=C:\Program Files\jdk1.6.0_45" %CATALINA_HOME%\bin\startup.bat --------------------------- ---startTomcat7_jdk7.bat--- @echo off set "CATALINA_HOME=C:\dev\apache-tomcat-7.0.55" set "TITLE=Tomcat 7.0.55 on JDK 1.7.0_67" set "JAVA_HOME=C:\Program Files\jdk1.7.0_67" %CATALINA_HOME%\bin\startup.bat --------------------------- ---startTomcat7_jdk8.bat--- @echo off set "CATALINA_HOME=C:\dev\apache-tomcat-7.0.55" set "TITLE=Tomcat 7.0.55 on JDK 1.8.0_20" set "JAVA_HOME=C:\Program Files\jdk1.8.0_20" %CATALINA_HOME%\bin\startup.bat --------------------------- ---startTomcat8_jdk7.bat--- @echo off set "CATALINA_HOME=C:\dev\apache-tomcat-8.0.9" set "TITLE=Tomcat 8.0.9 on JDK 1.7.0_67" set "JAVA_HOME=C:\Program Files\jdk1.7.0_55" %CATALINA_HOME%\bin\startup.bat --------------------------- ---startTomcat8_jdk8.bat--- @echo off set "CATALINA_HOME=C:\dev\apache-tomcat-8.0.9" set "TITLE=Tomcat 8.0.9 on JDK 1.8.0_20" set "JAVA_HOME=C:\Program Files\jdk1.8.0_20" %CATALINA_HOME%\bin\startup.bat --------------------------- (Again, Tomcat8 requires JDK7 or JDK8, e.g. jdk1.7.0_55 or jdk1.8.0_20 in our case) Notice, usage of "" (double quotes) is not intuitive on Windows, to accommodate for spaces in the paths. Try to avoid spaces in your Windows paths if you can :)) You could use these scripts to add additional settings, such as memory sizing, preferring IPv4, garbage collection and other JVM settings, use CATALINA_OPTS to provide these options. 8. To stop your process, just press CTRL+C in the Tomcat popup window. Alternatively, you can run the shutdown scripts, e.g. C:\dev\apache-tomcat-6.0.41\bin\shutdown.bat C:\dev\apache-tomcat-7.0.55\bin\shutdown.bat C:\dev\apache-tomcat-8.0.9\bin\shutdown.bat 9. That's it! This will get you started with a minimum disruption to your Windows machine (no installation, no Windows services, no Windows registry changes, no environment variable setup, etc...) I forgot to add, your Windows firewall might ask you to "Allow access" to your Java process to act as a server, i.e. just click "Allow" button if it comes up. Let us know if you have any questions, or if you are working on a Linux/Mac environment - specify your Linux distroy, e.g. Ubunut, CentOS, etc... I would take a similar approach on Linux distros, no installation (no yum or aptget install, etc...) just create scripts that will start your Tomcat instances, the way you would like. Also, you will be getting the latest code with the latest bug fixes, no need to wait for Linux vendors to update to the latest Tomcat versions (I am looking at you "yum" :) Hope this helps. Cheers! Neven