{"id":188,"date":"2026-10-12T16:51:32","date_gmt":"2026-10-12T16:51:32","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/03\/09\/why-and-how-to-use-jetty-in-mission-critical-production\/"},"modified":"2026-10-12T16:51:32","modified_gmt":"2026-10-12T16:51:32","slug":"why-and-how-to-use-jetty-in-mission-critical-production","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/why-and-how-to-use-jetty-in-mission-critical-production\/","title":{"rendered":"Embedded Jetty for Mission-Critical Production: Deployment Model, Trade-offs, and Operations"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Embedding Jetty means shipping your Java application and its web container together as a single runnable unit. For DevOps teams operating critical services, this model can reduce environment drift, simplify rollback, and keep test and production behavior closer together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide explains the production pattern described in the original post, where it helps most, and what you must explicitly design for monitoring, security, load balancing, and operational consistency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Originally published on 2010-03-09; fully revised and updated.<\/em><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/03\/how-to-use-jetty.png\" alt=\"How to use Jetty in production\" \/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">What embedded Jetty changes in production<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In a traditional Java setup, multiple applications are deployed into a shared application server. In an embedded model, each application carries its own server runtime (Jetty libraries) and starts from its own <strong>main<\/strong> method. Practically, this shifts control from platform-level deployment to application-level deployment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The original seminar example used this model to avoid server-level dependency constraints and to make deployment as simple as replacing one JAR with another.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deployment model: one artifact, minimal host prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The original post demonstrates packaging and shipping a standalone artifact (example project: <a href=\"http:\/\/svn.brodwall.com\/demo\/embedded-container\/\">embedded-container sample application<\/a>) and requiring only a JVM on the target host.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript language-bash\">mvn clean install\nscp server\/target\/app<span class=\"hljs-number\">-1.0<\/span>.onejar.jar appuser@appserver:<span class=\"hljs-regexp\">\/home\/<\/span>appuser\/test-env1\/\nssh appuser@appserver <span class=\"hljs-string\">\"cd \/home\/appuser\/test-env1\/ &amp;&amp; java -jar app-1.0.onejar.jar &amp;\"<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This enables straightforward rollback (replace artifact with a previous one) and easy horizontal scaling (run multiple instances with separate ports and process supervision).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why teams adopt this pattern<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Runtime independence:<\/strong> each service can evolve JVM and library choices without coordinating every change across a shared server platform.<\/li><li><strong>Dependency control:<\/strong> application dependencies are bundled and versioned with the service, reducing classpath surprises from server-provided libraries.<\/li><li><strong>Simpler release mechanics:<\/strong> deployment and rollback are artifact operations rather than app-server console operations.<\/li><li><strong>CI\/CD friendliness:<\/strong> immutable artifacts map cleanly to pull- or push-based deployment workflows.<\/li><li><strong>Test and production parity:<\/strong> you can start Jetty inside tests (example from the original post: <a href=\"http:\/\/svn.brodwall.com\/demo\/embedded-container\/embedded-container-web\/src\/test\/java\/no\/steria\/embeddedcontainer\/web\/HelloWebTest.java\">JUnit-based Jetty startup<\/a>), reducing server-behavior differences between environments.<\/li><li><strong>Operational clarity:<\/strong> operations teams can work with standard process controls (start, stop, status, logs) per service.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Operational capabilities you must explicitly own<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When you stop relying on a full external app server, you gain control but also inherit explicit responsibilities.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Monitoring and health checks<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">At minimum, write logs to a known location and expose a health endpoint that checks application-critical dependencies (database, downstream services, file shares, queues).<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript language-bash\">curl -fsS http:<span class=\"hljs-comment\">\/\/127.0.0.1:8080\/health<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Load balancing and session behavior<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Embedded Jetty does not automatically provide cluster routing behavior. Handle load balancing at reverse proxy, ingress, or network tiers, and decide whether you need sticky sessions. The original post points to Jetty-related proxy\/session guidance here: <a href=\"http:\/\/docs.codehaus.org\/display\/JETTY\/Configuring+mod_proxy\">Configuring mod_proxy<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Security boundaries<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The source notes JAAS support and SSO patterns where identity is forwarded via HTTP headers. In production, this only works safely when those headers are injected by a trusted upstream component and spoofed headers are stripped at the edge.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Consistency across services<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Standardize service layout and operations: startup commands, log paths, config conventions, health URLs, and runbooks. This keeps multi-service operations manageable even when each app owns its runtime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deployment and runtime workflow<\/h2>\n\n\n\n<pre class=\"mermaid\">\nflowchart TD\n    A[Build with Maven] --> B[Create runnable artifact]\n    B --> C[Publish artifact]\n    C --> D[Copy or pull to target host]\n    D --> E[Start java jar process]\n    E --> F[Serve traffic behind proxy]\n    E --> G[Expose health endpoint]\n    G --> H[Monitoring checks]\n    E --> I[Write logs]\n    I --> J[Central log collection]\n    H --> K{Healthy}\n    K -- no --> L[Restart or rollback]\n    K -- yes --> M[Continue serving]\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Minimal embedded Jetty bootstrap example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A small bootstrap class illustrates the model: the application constructs and starts Jetty directly.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript language-java\">public <span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">App<\/span> <\/span>{\n    public <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> main(<span class=\"hljs-built_in\">String<\/span>&#91;] args) throws Exception {\n        int port = Integer.parseInt(System.getProperty(<span class=\"hljs-string\">\"server.port\"<\/span>, <span class=\"hljs-string\">\"8080\"<\/span>));\n\n        Server server = <span class=\"hljs-keyword\">new<\/span> Server(port);\n        ServletContextHandler context = <span class=\"hljs-keyword\">new<\/span> ServletContextHandler(ServletContextHandler.SESSIONS);\n        context.setContextPath(<span class=\"hljs-string\">\"\/\"<\/span>);\n        context.addServlet(HealthServlet.class, <span class=\"hljs-string\">\"\/health\"<\/span>);\n        context.addServlet(AppServlet.class, <span class=\"hljs-string\">\"\/*\"<\/span>);\n\n        server.setHandler(context);\n        server.start();\n        server.join();\n    }\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Externalize runtime settings rather than hardcoding them:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript language-properties\">server.port=<span class=\"hljs-number\">8080<\/span>\napp.environment=production\nlog.dir=<span class=\"hljs-regexp\">\/var\/<\/span>log\/myapp\nhealth.check.dependencies=<span class=\"hljs-literal\">true<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Embedded Jetty vs shared application server<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Option<\/th><th>Strengths<\/th><th>Trade-offs<\/th><th>Best for<\/th><\/tr><\/thead><tbody><tr><td>Embedded Jetty per application<\/td><td>Strong app isolation, consistent packaging, easy rollback, simpler per-service CI\/CD<\/td><td>You must implement operational standards yourself (health, supervision, conventions)<\/td><td>Service-oriented teams that want independent release velocity<\/td><\/tr><tr><td>Shared external application server<\/td><td>Centralized platform controls and shared operational model<\/td><td>Cross-app dependency coupling, slower coordinated upgrades, potential classpath conflicts<\/td><td>Environments with strict centralized middleware governance<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Best practices for mission-critical use<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Treat the deployable artifact as immutable and versioned.<\/li><li>Use process supervision (systemd, container orchestrator, or equivalent) rather than ad-hoc background processes.<\/li><li>Make health checks dependency-aware, not just process-aware.<\/li><li>Keep config external and environment-specific.<\/li><li>Define a standard service contract: ports, logs, metrics, startup, shutdown, and alerting behavior.<\/li><li>Validate authentication header trust boundaries at the reverse proxy layer.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Historical reference from the original post:<\/strong> <a href=\"http:\/\/www.javaworld.com\/community\/?q=node\/4133\" target=\"_blank\" rel=\"noopener\">http:\/\/www.javaworld.com\/community\/?q=node\/4133<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Running Jetty as an embedded server packages your app and runtime into one deployable artifact. This guide explains why teams use this model, how to deploy it, and what operational controls you must own.<\/p>\n","protected":false},"author":1,"featured_media":4137,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[3452,1122,3113,3449,3454,1806,3446,3455,3447,3448,3453,213,1980,842,3451,3450],"class_list":["post-188","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorised","tag-application-server","tag-guide","tag-how-to","tag-how-to-use-jetty","tag-how-to-use-jetty-in-test-environment","tag-instruction","tag-jetty","tag-jetty-advantages-in-test-environment","tag-mission-critical","tag-production","tag-test-environment","tag-tutorial","tag-use","tag-why","tag-why-jetty","tag-why-use-jetty"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=188"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/188\/revisions"}],"predecessor-version":[{"id":79018,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/188\/revisions\/79018"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4137"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}