This is a a companion article to 5.0 Zero Footprint Tomcat Instances on Ubuntu.
On Windows we can not make it totally portable and we can make use of multiple instances.
You trade the capability of multiple instances for not being able to having the "windows installer" setup the gui system tray, but that's not a necessary function.
Manually Setup JRE
The main advantage is here is there are no entries in your registry and no automatic updates of Java (which I find can cause problems).
I install the version of Java I want on a test machine such as a VM and then copy the uncompressed Java folder over to your server and rename it to C:\opt\apache\java.
For older of Java versions go to the Java Archives site.
Manually Setup Tomcat
Tomcat on Windows is also set up to run without requiring an installation. Some of this stuff is done by the Tomcat installer version, however, the installer can not handle multiple instances for vertical scaling. Investing the time in this article will allow you full control.
The first step is to download the zip version of Tomcat for Windows.
Unzip the folder to C:\opt. We will use the convention, C:\opt\apache\tomcat.0. The letter a designates an instance. As we scale up, you can have another instance called b, c and so forth.
Running Tomcat with a specific JRE version
Create a file called setenv.bat with the following contents using a plain text editor such as notepad,
I've since found a more portable option using "$CATALINA_HOME" have only verified this works on my local Windows 7 machine. I still have to try this on a real server but it should work..
Verify your change using version.bat you will see the following results,
That's it, Tomcat will actually run and start if you run it from the command line, however, Windows is not designed to run command line applications so see the next section.
Automatic Startup and Shutdown of Tomcat
In Windows, you probably want to make use of Windows Services to automatically startup, shutdown and even stop and start Tomcat.
If successful you will see the following,
I have proven and working used, service.bat install tomcat0 but never with the period. The period may not work. Somebody validate for me.
We have now added Tomcat as a service to the windows registry. However, there is no reference yet to what version of java should be used with the service.
We will now issue commands to update the registry. If you want to see the updates in real time Start the registry,
- Click Start, Run
- Type, regedit and hit Enter to see the registry
- Click Edit, Find
- Search for tomcat.0
Interestingly using JavaHome instead of jvm in the above commands seems to work too. Not sure of the difference.
Refer to the Tomcat Windows Service How-To if you need to configure more options.
Tin says, re-reading my notes here, I set the JavaHome in the Windows service, but with more thought, I think JavaHome is meant for a JDK. Why not set a JREHome? The Tomcat documentation does not show a JREHome, but it might work. Try this out on a test machine sometime. Also, I just confirmed that not setting JavaHome or any kind of Java works fine with the service. Windows might only need the --Jvm setting.
Tomcat Icon on System Tray
Finally, you can add Tomcat to the Windows System Tray.
First open notepad and put in the following text changing the particulars to your particular instance of Tomcat,
Save the file as tomcat.0-system-try.reg
Put the file on the server and double-click the file. You will be prompted with a warning dialog as this is modifying the windows registry and provided a success message once registry the entry has been added.
Log off and log on again. You should see the Tomcat Icon named to your particular instance in your system tray.
The registry entry equates to automatically running the following command upon login,
Finally log out and log back in. You should now see the tomcat icon on the system tray.
Setup Tomcat Instance 1
To set up another instance of Tomcat, I would call it tomcat.1, simply copy the tomcat.0 directory, change the ports as outlined in Ubuntu 5.0 Zero Footprint Tomcat 6.x & Instances. There is one difference in the Ubuntu steps and that is there is no grep command. Instead, provided you have Windows XP or higher you can use findstr,
Next, repeat Automatic Startup and Shutdown of Tomcat and Tomcat Icon on System Tray with adjustment for the different name and directory.
http://tomcat.apache.org/tomcat-6.0-doc/windows-service-howto.html#Tomcat6w - Background on how to add to system try.