Tomcat is produced by the Apache Software Foundation and is an open source, Java, web server and servlet container. It is often known as just Tomcat rather than Apache Tomcat or it's old name Jakarta Tomcat. The official website is Apache Tomcat - Welcome! which is a great starting point. Tomcat implements the Java Servlet and JavaServer Pages specifications. I have used it on both Windows and Linux and found it to be flexible and robust, not just in development and testing but also in production.
Sometimes configuring Tomcat is not the easiest thing, so, let's see if I can help with a couple of pointers.
Tomcat installations are generally very easy, on Windows you will find an "Apache Software Foundation" directory in "Program Files", under which you will find a Tomcat directory, whose exact name will depend on the version you have, then you will see several subdirectories, a couple of which are worth highlighting:
Note that on Windows all these files are "protected", so if you want to change the config files you will need to run your text editor as an administrator.
It is also worth noting that for some of the elements below where Tomcat expects a file path then it needs a Unix style path. On Linux using /apps/myapp/*.jar
works fine, however if you are using Windows and you have C:\Apps\MyApp\*.jar
then in Tomcat this becomes /C:/Apps/MyApp/*.jar
.
These are all defined in your tomcat-users.xml file, this is where you go when you have forgotten your admin password.
If your webapps depend on JAR files, then it is best to specify their location in the catalina.properties file. I normally set the shared.loader, to something like this: shared.loader=/myapp/libs/*.jar
, this allows all webapps access but not Tomcat itself, it is the same as putting your jars in the "shared/lib" directory. I find this useful for keeping the jar files with the app rather than having to put them in Tomcat folders.
There are times when you want Tomcat to load WebApps from application directories and not Tomcat ones. This is done by modifying server.xml, the XPath to the correct element to change is "/Server/Service/Engine/Host/@appBase". When you install Tomcat you can specify that "docs", "examples" and the "manager" are installed. If you need these then you can copy them to the new directory. You can create two host elements in server.xml but the name element needs to be different which means you can't use the same hostname in the url. Your host element should look something like this <Host name="localhost" appBase="/myapp/webapps" unpackWARs="true" autoDeploy="true">
.
I know some people prefer to run Tomcat via a script on Windows as this is more like Linux, however I have found running it as a Windows Service to work well and do everything I have needed. The best thing to do is run the "Monitor Tomcat" shortcut from the Start Menu, this then gives you a System Tray icon. From the tray icon starting and stopping Tomcat is very easy but I find double clicking it for the Configure dialog very convenient. If you need to change the memory settings you can just type the values you want straight into the Java tab, which is equivalent to -Xms1024m -Xmx1024m
. In the Java Options section you can also input any -X JVM options you need, like -XX:PermSize=64M
-XX:MaxPermSize=128M
, however do put the options on separate lines.
There is a useful article Enhancing Tomcat Logging For Improved Forensics | Symantec Connect on logging. Well worth a read if you need to run Tomcat.