On this page
- 1. · Concept & Definition
- 2. · Why It Matters
- 3. · How It Works
- Deep Dive — What Happens When a WAR Is Deployed
- 4. · Java / Jakarta EE Code Examples
- 5. · Configuration, Defaults & Diagnostics
- 6. · Production Usage Patterns
- 7. · Common Pitfalls & Misconceptions
- 8. · Best Practices
- 9. · Architect's Perspective & Trade-offs
- 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.

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 service | What components get |
|---|---|
| Request dispatch | URL mapping to servlets, filters, REST resources |
| Concurrency | Pooled (or virtual) threads; one instance serving many requests |
| Injection | @Inject, @Resource, @PersistenceContext resolved by the container |
| Security | Declarative constraints, authentication mechanisms, isUserInRole |
| Lifecycle | init/destroy, listeners, @PostConstruct/@PreDestroy |
| Naming | java:comp/env lookups for data sources and configuration |
Components
| Component type | Specification | Role |
|---|---|---|
| Servlet | Jakarta Servlet | Low-level request handler |
| Filter / Listener | Jakarta Servlet | Interception and lifecycle observation |
| JSP / Facelets page | Jakarta Pages / Faces | Server-side view rendering |
| REST resource | Jakarta RESTful Web Services | Resource-oriented HTTP APIs |
| WebSocket endpoint | Jakarta WebSocket | Bidirectional messaging |
| CDI bean | Jakarta CDI | Business 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 style | Example | Characteristic |
|---|---|---|
| Hot deploy directory | Copy WAR to webapps/ or deployments/ | Simple; risky in production |
| Admin CLI / REST | jboss-cli deploy, asadmin deploy | Scriptable, auditable |
| Immutable image | Runtime + app baked into a container image | Reproducible; 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.

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.
| Aspect | WAR | EAR |
|---|---|---|
| Contains | One web module | Several modules + shared libraries |
| Descriptor | WEB-INF/web.xml (optional) | META-INF/application.xml (optional) |
| Class loading | One web-app class loader (child-first in many containers) | Hierarchy: EAR libs visible to modules |
| Runtime | Servlet container or app server | Application server (Platform profile) |
| Modern usage | Common | Legacy / large monoliths |
Lifecycle

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
<!-- 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>@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();
}
}$ 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.jar5· Configuration, Defaults & Diagnostics
| Item | Default / behaviour |
|---|---|
| Context root | WAR file name (e.g. orders.war → /orders), overridable per server |
web.xml | Optional since Servlet 3.0; metadata-complete="true" disables annotation scanning |
beans.xml | Optional; without it CDI uses annotated discovery mode |
Scope provided | Jakarta EE APIs must not be bundled in WEB-INF/lib when the server supplies them |
| Class loading | Web 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.
# 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> 5s6· 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.
andjakarta.` 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
contextInitializedwith shutdown incontextDestroyed. - Keep configuration external (environment, MicroProfile Config) rather than editing descriptors per environment.
9· Architect's Perspective & Trade-offs
| Packaging choice | Strength | Weakness | Use when |
|---|---|---|---|
| Thin WAR on shared server | Small artefacts, central ops | Shared failure domain | Traditional managed estates |
| WAR on dedicated server image | Isolation, standard APIs | Larger image | Containerised Jakarta EE |
| Runnable JAR | Self-contained, simple CI/CD | Runtime updates need rebuild | Microservices |
| EAR | Single unit for multi-module apps | Coupled release, heavy | Legacy monoliths only |
10· Interview Q&A
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.
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.
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.
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.
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.
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.