Skip to content

Commit 66145d5

Browse files
brunoborgesCopilot
andcommitted
Add built-in HTTP server pattern (JDK 18, jwebserver)
Shows jwebserver CLI and SimpleFileServer API vs external server setup. Inserted between compact-object-headers and aot-class-preloading. 90 snippets. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 22f8a9c commit 66145d5

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

content/tooling/aot-class-preloading.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"state": "experimental",
3535
"description": "Available in JDK 25 LTS (JEPs 514/515, Sept 2025). Experimental."
3636
},
37-
"prev": "tooling/compact-object-headers",
37+
"prev": "tooling/built-in-http-server",
3838
"next": "language/default-interface-methods",
3939
"related": [
4040
"tooling/jshell-prototyping",
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"id": 91,
3+
"slug": "built-in-http-server",
4+
"title": "Built-in HTTP server",
5+
"category": "tooling",
6+
"difficulty": "beginner",
7+
"jdkVersion": "18",
8+
"oldLabel": "Java 8",
9+
"modernLabel": "Java 18+",
10+
"oldApproach": "External Server / Framework",
11+
"modernApproach": "jwebserver CLI",
12+
"oldCode": "// Install and configure a web server\n// (Apache, Nginx, or embedded Jetty)\n\n// Or write boilerplate with com.sun.net.httpserver\nHttpServer server = HttpServer.create(\n new InetSocketAddress(8080), 0);\nserver.createContext(\"/\", exchange -> { ... });\nserver.start();",
13+
"modernCode": "// Terminal: serve current directory\n$ jwebserver\n\n// Or use the API (JDK 18+)\nvar server = SimpleFileServer.createFileServer(\n new InetSocketAddress(8080),\n Path.of(\".\"),\n OutputLevel.VERBOSE);\nserver.start();",
14+
"summary": "Java 18 includes a built-in minimal HTTP server for prototyping and file serving.",
15+
"explanation": "JDK 18 added a simple, zero-dependency HTTP file server accessible via the jwebserver command-line tool or the SimpleFileServer API. It serves static files from a given directory with no configuration needed. The CLI tool is ideal for quick prototyping, testing, and ad-hoc file sharing — no external dependencies or frameworks required. The API allows programmatic use with customizable handlers and output levels.",
16+
"whyModernWins": [
17+
{ "icon": "🚀", "title": "Zero setup", "desc": "Run jwebserver in any directory — no installation, config, or dependencies needed." },
18+
{ "icon": "📦", "title": "Built into the JDK", "desc": "Ships with every JDK 18+ installation, always available on any machine with Java." },
19+
{ "icon": "🧪", "title": "Great for prototyping", "desc": "Serve static files instantly for testing HTML, APIs, or front-end development." }
20+
],
21+
"support": {
22+
"state": "available",
23+
"description": "Available since JDK 18 (March 2022)"
24+
},
25+
"prev": "tooling/compact-object-headers",
26+
"next": "tooling/aot-class-preloading",
27+
"related": [
28+
"io/http-client",
29+
"tooling/single-file-execution",
30+
"tooling/jshell-prototyping"
31+
]
32+
}

content/tooling/compact-object-headers.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"description": "Finalized in JDK 25 LTS (JEP 519, Sept 2025)."
3636
},
3737
"prev": "tooling/jfr-profiling",
38-
"next": "tooling/aot-class-preloading",
38+
"next": "tooling/built-in-http-server",
3939
"related": [
4040
"tooling/jshell-prototyping",
4141
"tooling/single-file-execution",

0 commit comments

Comments
 (0)