Tomcat 8中common.loader、server.loader与shared.loader的差异咨询
Nice question! Let's break down the key differences between these three class loader configurations in Tomcat 8, even though the official docs prioritize explaining common.loader:
common.loader
This is the most widely referenced loader, and for good reason. Classes loaded here are visible to both Tomcat's internal core components (like the Catalina container, connectors, and management tools) and every deployed web application. It's the "global shared" layer—think of it as the base set of classes that everyone (Tomcat and your apps) needs. By default, it includes most of the core JARs in Tomcat'slibdirectory, such asservlet-api.jar.server.loader
This loader is strictly for Tomcat's internal use only. Classes defined here are completely invisible to your web applications—they're only accessible to Tomcat's own server-side components (like JMX monitoring, container lifecycle managers, or custom Tomcat extensions you build). It has higher priority thancommon.loader, so Tomcat will load these classes first before pulling in anything from the common layer. Use this when you have code that should never be exposed to your web apps.shared.loader
The flip side ofserver.loader, this loader makes classes visible only to your web applications, not to Tomcat's internal components. It's perfect for sharing common libraries across multiple web apps (like a custom utility JAR, or a third-party library used by all your apps) without having to copy the JAR into each app'sWEB-INF/libfolder. This keeps your deployments lean and ensures consistent versions across apps, while keeping those classes isolated from Tomcat's own runtime.
A quick note: The official docs focus on common.loader because it's the most commonly used configuration for general global class sharing. server.loader and shared.loader are more specialized, for when you need tighter isolation between Tomcat's core and your application code.
内容的提问来源于stack exchange,提问作者frank

