ArchitectMind
  1. Home
  2. Java Ecosystem
  3. Book 3 · Jakarta EE & Enterprise Java
  4. Volume I
  5. Jakarta EE Web Architecture
Book 3 · Volume I — Web Tier & Web Application Technologies · Topic 1.3

Jakarta EE Web Architecture

Web container, Components, Deployment, WAR, EAR, Lifecycle

8 min readStage 1 · Foundations6 interview questions
On this page
  1. 1. · Concept & Definition
  2. 2. · Why It Matters
  3. 3. · How It Works
  4. Deep Dive — What Happens When a WAR Is Deployed
  5. 4. · Java / Jakarta EE Code Examples
  6. 5. · Configuration, Defaults & Diagnostics
  7. 6. · Production Usage Patterns
  8. 7. · Common Pitfalls & Misconceptions
  9. 8. · Best Practices
  10. 9. · Architect's Perspective & Trade-offs
  11. 10. · Interview Q&A

1· Concept & Definition

Jakarta EE is the vendor-neutral set of enterprise Java specifications governed by the Eclipse Foundation (successor to Java EE; package namespace jakarta.* since Jakarta EE 9). Its web architecture is a container model: applications are packaged as components in standard archives, deployed to a runtime, and managed through a defined lifecycle. Jakarta EE 11 (2025) requires Java SE 17 or newer and is organised into three profiles.

Jakarta EE 11 profiles — Core ⊂ Web ⊂ Platform
Figure 1.3.1 — Jakarta EE 11 profiles — Core ⊂ Web ⊂ Platform

2· Why It Matters

  • Standard packaging and lifecycle make applications portable across certified runtimes.
  • Profiles let architects select a minimal API surface for microservices or a full platform for integration-heavy systems.
  • Understanding class loading and lifecycle explains redeploy leaks, library conflicts and startup ordering.

These points become concrete the moment a system moves between runtimes. A team taking a WAR from WildFly to Open Liberty, or from a shared server to a container image, discovers exactly which parts were standard and which were vendor configuration: the archive layout, annotations and lifecycle callbacks travel unchanged, while data-source definitions, security realms and class-loading tweaks do not. Knowing the architecture also shortens incident diagnosis. A NoSuchMethodError after a library upgrade, a request that passes a filter but never reaches its servlet, or a pod whose memory grows after every in-place redeploy all have causes that sit in the container model rather than in business code, and they are found far faster by someone who knows how the container assembles and runs an application.

3· How It Works

Web container

The web container hosts web components and provides their runtime services: request dispatch, threading, security constraints, sessions, naming (JNDI), injection (CDI) and lifecycle callbacks. Components never manage sockets or threads directly; they receive callbacks from the container.

Container serviceWhat components get
Request dispatchURL mapping to servlets, filters, REST resources
ConcurrencyPooled (or virtual) threads; one instance serving many requests
Injection@Inject, @Resource, @PersistenceContext resolved by the container
SecurityDeclarative constraints, authentication mechanisms, isUserInRole
Lifecycleinit/destroy, listeners, @PostConstruct/@PreDestroy
Namingjava:comp/env lookups for data sources and configuration

Components

Component typeSpecificationRole
ServletJakarta ServletLow-level request handler
Filter / ListenerJakarta ServletInterception and lifecycle observation
JSP / Facelets pageJakarta Pages / FacesServer-side view rendering
REST resourceJakarta RESTful Web ServicesResource-oriented HTTP APIs
WebSocket endpointJakarta WebSocketBidirectional messaging
CDI beanJakarta CDIBusiness logic with scopes and injection

Deployment

Deployment installs an archive into a runtime. The container reads deployment descriptors and annotations, builds the effective configuration, creates a class loader and initialises components. Deployment can be a file drop (auto-deploy directory), an admin command/API, or build-time packaging of an application with its runtime (runnable JAR / container image).

Deployment styleExampleCharacteristic
Hot deploy directoryCopy WAR to webapps/ or deployments/Simple; risky in production
Admin CLI / RESTjboss-cli deploy, asadmin deployScriptable, auditable
Immutable imageRuntime + app baked into a container imageReproducible; redeploy = new image

WAR

A Web Application Archive is a ZIP with a defined layout. Everything under WEB-INF/ is private (never served directly); everything else is public static content.

WAR and EAR archive structures
Figure 1.3.2 — WAR and EAR archive structures

EAR

An Enterprise Application Archive groups multiple modules (WARs, EJB JARs, resource adapters) with shared libraries in lib/. It enables one deployment unit with shared class loading, historically used for large monoliths with EJB business tiers. In modern architectures EARs are rare; independent WARs or runnable JARs are preferred.

AspectWAREAR
ContainsOne web moduleSeveral modules + shared libraries
DescriptorWEB-INF/web.xml (optional)META-INF/application.xml (optional)
Class loadingOne web-app class loader (child-first in many containers)Hierarchy: EAR libs visible to modules
RuntimeServlet container or app serverApplication server (Platform profile)
Modern usageCommonLegacy / large monoliths

Lifecycle

Deployment lifecycle from deploy to undeploy
Figure 1.3.3 — Deployment lifecycle from deploy to undeploy

During startup the container fires ServletContextListener.contextInitialized, initialises servlets with load-on-startup, and only then routes requests. On undeploy it stops routing, calls destroy() on components and contextDestroyed on listeners, then releases the class loader. Any lingering reference to application classes (threads, ThreadLocals, JDBC drivers, static caches in parent loaders) prevents class-loader collection and leaks Metaspace on redeploy.

Deep Dive — What Happens When a WAR Is Deployed

Deployment is a pipeline rather than a single step, and most start-up failures can be placed in one of its stages. The container first opens the archive and creates the web-application class loader over WEB-INF/classes and WEB-INF/lib. It then builds the effective configuration by merging web.xml, any web-fragment.xml files inside library JARs, and the annotations found by scanning; metadata-complete="true" skips the scan, which noticeably shortens start-up for large WARs. ServletContainerInitializer implementations registered through META-INF/services run next, which is how frameworks such as Jakarta Faces register their servlets without any descriptor.

With the configuration known, the CDI container discovers beans and validates every injection point, so an unsatisfied dependency stops the deployment here rather than at the first request. Listeners then receive contextInitialized, servlets marked load-on-startup are initialised in order, and only after that is the context marked available and added to the request mapper. Undeploy runs the same stages in reverse, ending with the release of the class loader.

4· Java / Jakarta EE Code Examples

CODEMaven configuration for a Web Profile WAR
<!-- pom.xml: compile against the Jakarta EE 11 Web Profile API,
        provided by the server -->
<dependency>
    <groupId>jakarta.platform</groupId>
    <artifactId>jakarta.jakartaee-web-api</artifactId>
    <version>11.0.0</version>
    <scope>provided</scope>
</dependency>
<packaging>war</packaging>
JAVALifecycle hooks — start and stop application-owned resources symmetrically
@WebListener
public class AppLifecycle implements ServletContextListener {
    private ScheduledExecutorService scheduler;
 
    @Override public void contextInitialized(ServletContextEvent e) {
        scheduler = Executors.newSingleThreadScheduledExecutor();
        scheduler.scheduleAtFixedRate(() -> e.getServletContext().log("heartbeat"),
                                      0, 1, TimeUnit.MINUTES);
    }
    @Override public void contextDestroyed(ServletContextEvent e) {
        // prevents thread + class-loader leak on redeploy
        scheduler.shutdownNow();
    }
}
TERMINALInspecting a WAR
$ jar tf orders.war | head
META-INF/MANIFEST.MF
index.html
WEB-INF/web.xml
WEB-INF/classes/com/acme/orders/OrderServlet.class
WEB-INF/lib/jackson-databind-2.17.2.jar

5· Configuration, Defaults & Diagnostics

ItemDefault / behaviour
Context rootWAR file name (e.g. orders.war → /orders), overridable per server
web.xmlOptional since Servlet 3.0; metadata-complete="true" disables annotation scanning
beans.xmlOptional; without it CDI uses annotated discovery mode
Scope providedJakarta EE APIs must not be bundled in WEB-INF/lib when the server supplies them
Class loadingWeb apps usually load WEB-INF classes before parent (servlet spec recommendation), except java.*/jakarta.* platform classes

When a deployment misbehaves, establish what the container actually built rather than what the source suggests. The effective context root, the libraries really packaged in WEB-INF/lib and the JAR a class was loaded from explain most packaging defects. Duplicate API JARs, a javax library that arrived transitively, or two versions of the same library are found in the dependency tree. Class-loader leaks after redeploys show up as a loaded-class count that never falls, and are confirmed with a heap dump by following the old class loader's path to GC roots.

JAVAInspecting what was packaged and loaded
# Platform APIs must have scope 'provided'
mvn dependency:tree | grep -E 'jakarta|javax'

# Libraries actually inside the WAR
jar tf target/orders.war | grep 'WEB-INF/lib/'

# Add to the server JVM options: log each class and its source JAR
-Xlog:class+load=info

# Class loaders and loaded classes; repeat after each redeploy
jcmd <pid> VM.classloader_stats
jstat -class <pid> 5s

6· Production Usage Patterns

  • Thin WAR on a managed server — application contains only its code and a few libraries; the server provides APIs.
  • Hollow/runnable JAR — server runtime packaged with the application for container images (Payara Micro, Liberty, WildFly bootable JAR).
  • Core Profile microservices — REST + CDI Lite + JSON, suitable for fast startup and native compilation.
  • Blue/green or rolling deployments of immutable images instead of in-place redeploys.

7· Common Pitfalls & Misconceptions

  • Bundling Jakarta EE API or implementation JARs in WEB-INF/lib — causes class conflicts with the server's versions.
  • *Mixing `javax. and jakarta.` libraries* — pre-EE 9 libraries do not work on Jakarta EE 9+ runtimes without migration.
  • Relying on hot redeploy in production — class-loader leaks accumulate Metaspace until restart.
  • Starting threads without stopping them in lifecycle callbacks.

8· Best Practices

  • Target the smallest profile that meets requirements; declare the API as provided.
  • Prefer one application per runtime and immutable deployments.
  • Pair every resource started in contextInitialized with shutdown in contextDestroyed.
  • Keep configuration external (environment, MicroProfile Config) rather than editing descriptors per environment.

9· Architect's Perspective & Trade-offs

Packaging choiceStrengthWeaknessUse when
Thin WAR on shared serverSmall artefacts, central opsShared failure domainTraditional managed estates
WAR on dedicated server imageIsolation, standard APIsLarger imageContainerised Jakarta EE
Runnable JARSelf-contained, simple CI/CDRuntime updates need rebuildMicroservices
EARSingle unit for multi-module appsCoupled release, heavyLegacy monoliths only

10· Interview Q&A

Q1L1 · BasicConcept

What is a WAR file?

A WAR, or Web Application Archive, is the standard deployment unit for a Jakarta web module: a ZIP file with a defined layout that any certified container understands. Static resources such as HTML, CSS and JavaScript sit at the root and are served directly. Everything under WEB-INF is private: compiled classes in WEB-INF/classes, third-party libraries in WEB-INF/lib and the optional web.xml descriptor, which the container reads but never serves. The file name usually becomes the context root, so orders.war is served at /orders. A good WAR is thin: it bundles the application and its own libraries but marks the Jakarta EE APIs as provided, because the server supplies them.

Q2L2 · IntermediateTrade-off

What is the difference between a WAR and an EAR?

A WAR holds one web module, while an EAR packages several modules, such as WARs, EJB JARs and resource adapters, plus shared libraries in lib/, as a single deployment for a full application server. The EAR also defines a class-loader hierarchy: libraries in its lib/ directory are visible to every module, which lets a web tier and an EJB tier share domain classes without duplicating them. The cost is coupling, because all modules are versioned, tested and released together, and one faulty module blocks the whole deployment. I would keep an EAR only to maintain an existing multi-module system; new work is packaged as independent WARs or runnable JARs.

Q3L2 · IntermediateConcept

What are the Jakarta EE profiles?

Profiles are standardised, TCK-tested subsets of Jakarta EE, and they are strictly nested. The Core Profile is the smallest: Jakarta REST, CDI Lite, JSON Processing and Binding, Interceptors and Annotations, aimed at microservices and native compilation. The Web Profile adds Servlet, Pages, Faces, WebSocket, Persistence, Transactions, Security, Bean Validation, Concurrency, full CDI and Enterprise Beans Lite, which covers most web applications. The full Platform adds Messaging, Batch, Connectors, Mail and full Enterprise Beans with remote and message-driven beans. Because each larger profile contains the smaller one, an application written for the Web Profile runs unchanged on any certified Platform server, which is what makes targeting the narrowest profile safe.

Q4L3 · Senior EngineerInternals

Why does redeploying a WAR repeatedly cause Metaspace growth?

Each deployment gets a fresh web-application class loader, and the old one can be garbage-collected only when nothing outside the application still references it or any class it loaded. Common culprits are threads the application started and never stopped, ThreadLocal values left on pooled container threads, JDBC drivers registered in the global DriverManager, and caches or listeners held by a parent class loader. A single surviving reference pins the whole loader with all its classes, so every redeploy adds another copy to Metaspace until the JVM fails with OutOfMemoryError: Metaspace. I diagnose it with a heap dump and the path to GC roots, and fix it by cleaning up in contextDestroyed.

Q5L4 · Technical ArchitectTricky

Why must Jakarta EE APIs be provided scope?

Because the runtime already supplies the API and its implementation, and a second copy in WEB-INF/lib competes with it. Containers usually refuse to load core jakarta.* classes from the application, but that filtering differs between servers, and bundled implementation JARs, such as another Hibernate, Weld or JSON provider, are not filtered at all. The same class loaded by two class loaders is two different types, so the result is ClassCastException, LinkageError or NoSuchMethodError that appear only on certain servers. Declaring jakarta.jakartaee-web-api as provided lets you compile against the API without shipping it. The exception is a plain servlet container or a runnable JAR, where those libraries must be bundled.

Q6L5 · Solution ArchitectDesign

How would you modernise a large EAR-based application?

I would modernise incrementally rather than rewrite. First map the modules, their shared libraries and their remote EJB calls, and move the application onto a current runtime, migrating javax to jakarta with tools such as OpenRewrite, so that later steps happen on a supported platform. Then choose a bounded area with a clear business owner, extract it as a separate WAR or service with its own data, and route traffic to it through a facade, the strangler pattern. Replace remote EJB coupling with REST or messaging, turn shared code into versioned artefacts, and ship immutable container images. Every step must be releasable on its own, so value arrives continuously and risk stays small.

Test your knowledge on this topic →Flashcards from this topic's 6 questions, filtered by level and type.

Free question pack

Get 100 free Core Java interview questions

Subscribe for the Book 1 question pack (PDF, every answer explained) and new tutorials once a week. No spam, unsubscribe anytime. What is in the pack?

Almost done! Check your inbox and click the confirmation link. Your download link arrives as soon as you confirm.