Java Basics: What Is Apache Tomcat?
Apache Tomcat, one of the most popular web server and Servlet container for Java code, is an open source project that was first released in 1999.
But what has made Tomcat so popular for Java developers? In this blog, we look at how Apache Tomcat is used in Java today, how it works, and compare it vs. Jetty, Weblogic, and Wildfly.
- What Is Tomcat Used For?
- How Does Tomcat Work?
- Is Tomcat Popular?
- Tomcat vs. Jetty
- Tomcat vs. JBoss / Wildfly
- Tomcat vs. WebLogic
An Abridged Apache Tomcat Overview
As the reference implementation of Java Servlet and Java Server Pages (JSP), Tomcat was started at Sun Microsystems, which later donated the code base to the Apache Software Foundation.
Since then, multiple volunteers from Sun contributed to the product which then led to a a top-level Apache project designation in 2005. Nowadays, Apache Tomcat is widely used by many companies as it implements many of the Java EE specifications, such as:
- Java Servlet
- JavaServer Pages,
- Java Expression Language,
- Java WebSockets.
The current version of Apache Tomcat is 9.x and it is still under the focus of development. The upcoming version 10 should bring support for Servlet 5.0, JSP 3.0, EL 4.0, WebSocket 2.0, and Authentication 2.0. Tomcat versions 9 and 10 support Java 8 and later.
For those who need more from the Java EE implementation, TomEE is the way to go. It's built on top of Apache Tomcat and adds support for more features of Java EE, including EJB or MyFaces.
What Is Tomcat Used For?
Tomcat is used for web applications written in Java that don't require full Java EE specifications, but still need a reliable tool.
The reason Tomcat is not really a full application server is because it acts only as a Web server and Servlet container. It doesn’t provide the full feature set from the Java EE, but that isn't necessarily a disadvantage. Many applications require just the features that Tomcat provides, so it doesn't make sense to go with the heavier tools. You can use Apache Tomcat for production applications that process thousands of requests if the features it provides is enough. In any case, Tomcat is a production-ready tool.
Is Tomcat Still Popular?
Find out how Tomcat compares to other application servers in the 2021 Java Developer Productivity Report.
How Does Tomcat Work?
Tomcat is a platform-independent tool, and, as long there is Java installed, the installation is a straightforward process. You just need to download the desired version from the official website and then unpack it on your file system. You can verify that Tomcat is installed properly by running the server using a startup script in the $CATALINA_BASE/bin folder.
Once you start the server open your internet browser and navigate to URL http://localhost:8080 (if the default configuration is used). If you see a similar page as on the picture below, that means Tomcat was properly installed.
Deploying the application on to the server is really easy. Tomcat supports deployment on the startup, which means you copy compressed (.WAR) or non-compressed (exploded web application) to the right directory, which is $CATALINA_BASE/webapps/.
If you prefer deploying the application on the fly, you can deploy the application to a running Tomcat server in the Tomcat Web Application Manager GUI. All the deployed applications can be managed via the Manager App in the Tomcat.
There are a few main components that Tomcat uses. The component Catalina is the actual Servlet container that implements the specification for Servlets and JavaServer Pages. The other component, Coyote, is handling all the HTTP communication and forwards the requests to the Tomcat Engine (Catalina).
Is Tomcat Popular?
As we note in our 2020 Java Developer Productivity Survey, Tomcat is very popular -- boasting a market share of over 60%.
This is due to the fact that it is a very lightweight tool and it is free. It offers the most basic functionality needed by many applications, its startup time is quite fast, and the redeploy times are much lower compared to other tools on the market.
If you ever run into an issue, the extensive documentation will likely help you find a solution. Tomcat has very good documentation available, and what is not in the official documentation, you find it on the internet as there are many wide ranges of tutorials available.
It's also important to note that Tomcat isn't a one size fits all solution for Java applications. Picking the right server always depends on the needs presented by the application.
Tomcat vs. Jetty
When it comes to the lightweight servers, Tomcat is most often compared to Jetty. Jetty is an HTTP server and Servlet container that is often used as an embedded server. For a long time, Jetty was the only tool capable of running in embedded mode. As of now, Tomcat is already capable of running in the embedded mode as well.
Both tools are open source, with Tomcat developed under the Apache 2.0 open source license and the Jetty license is managed by the Eclipse Foundation and is available with Apache 2.0 and Eclipse Public License 1.0.
|Tomcat Benefits||Jetty Benefits|
|Licensed with Apache 2.0||Prioritize needs of the user community|
|High market share||Small memory footprint|
|Focus on being up to date with the latest specification||Embeddable|
|Very well documented|
Both tools are very good and share many of the same features. While Tomcat is very well documented and has a big market share, for applications that are focused on low memory footprint, Jetty might be a slightly better choice.
Tomcat vs. WebLogic
The full implementation of Java EE standards is available in Oracle WebLogic Server. WebLogic is a commercial project currently developed by Oracle Corporation and thus is licensed and requires buying a license in order to use for commercial purposes.
WebLogic has several benefits over Tomcat, in that it supports distributed transactions using transaction managers, supports Enterprise Java Beans, and offers other functionalities that make it a good choice for commercial and enterprise applications. In addition, WebLogic comes with a great administration console that makes the management of the server a seamless process.
|Tomcat Benefits||WebLogic Benefits|
|Open source||Developed by Oracle Corporation|
|Quick start and redeploys||Supports Enterprise Java Beans (EJB)|
|Can be used freely for commercial projects<||Transactions management|
If your application requires most or all the features of Java EE and you need commercial support, WebLogic is the way to go. Be warned, however, it's not free.
Tomcat vs. JBoss / Wildfly
Another application server that implements full Java EE specification is JBoss AS. Developed by Red Hat, JBoss Application Server is an open source platform that offers a rich feature set and is available for all the platforms where Java is available. For those confused about the name, JBoss AS was renamed to WildFly, which is the community version of the application server that has a Java EE8 certification.
Red Hat doesn’t provide support for the community project for WildFly. But, due to its popularity, there are many tutorials on the web — as well as the big userbase on StackOverflow. If your main goal is to use JBoss in the production environment, you may consider subscribing to Red Hat as it is the only way how to get support. The commercially supported product is called JBoss EAP and it is actually derived from the WildFly community project.
|Tomcat Benefits||JBoss EAP / WildFly Benefits|
|Open source||Full Java EE application server for free (WildFly)|
|Quick start and redeploys||Commercial support (JBoss EAP|
|Java EE 8 certified|
Choosing the right application server can be a tough decision for Java development teams. But one thing is clear, you always need to consider the needs of the application. This will prevent a situation where you would choose a tool that offers more than the application needs, adding unwanted load to everything else – memory, startup times, and configuration.
If you are not sure what server is good for you, you can start with Tomcat and see if it is enough. As you saw in the section “How does Tomcat work?” the installation and deployment take a matter of minutes.
While Apache Tomcat is not really a “pure” application server, comparing it with the other tools mentioned above should give you insight into how each tool should be applied. For lightweight tools, the main competitor for Tomcat is Jetty, as both implement just some features from Java EE. If you require enterprise support, then you should consider using JBoss EAP.
Want to hear more discussion on the most used application servers in Java? This webinar discusses the results of our 2020 Java Developer Survey, which asked developers around the world about the tools they use most.
If you're looking for additional insight into popular Java server technologies, be sure to check out the resources below.
- Blog - 2020 Java Technology Report
- White Paper - 2020 Java Developer Productivity Report
- Webinar - 2020 Trends in Java Development
Want to see how JRebel can help speed up your Java development? Start skipping redeploys today with a free JRebel trial.