rgoussu@goussu: ~/library/java/jdk-and-tools
~/library/java/jdk-and-tools cat jwebserver.md

jwebserver — the minimal static file server

# JDK 18's zero-config static HTTP file server (JEP 408) for prototyping and local file serving, not for production.

Conceptsaved 2026-08-09 #java#tooling#http#protocols

Overview

jwebserver (Java 18, JEP 408) is a command-line static file server: run it in a directory and it serves that directory's contents over HTTP, with directory listings and request logging to the console. It exists for the "python -m http.server" niche — prototyping, sharing a build output, serving a docs folder, teaching HTTP — so you no longer reach outside the JDK for it.

Key points

  • Defaults: binds 127.0.0.1:8000 serving the current directory; -b 0.0.0.0 to expose, -p for port, -d for directory, -o verbose for full request/response header logging.
  • Built on com.sun.net.httpserver: the long-standing JDK-internal-but-supported HTTP server API; JEP 408 added SimpleFileServer and handler/filter factories so you can embed the same file-serving behaviour programmatically or via java -m jdk.httpserver.
  • GET/HEAD only: other methods get 405; it maps paths to files, guesses MIME types, and serves directory indexes — that is the whole feature set.
  • What it is not: no HTTPS/HTTP/2, no authentication, no servlets or dynamic content, not hardened for the open internet. For anything real, use a proper server or framework (Spring Boot's embedded Tomcat/Netty, Quarkus/Vert.x, Micronaut's Netty server).
  • Embeddable variant: SimpleFileServer.createFileServer(addr, path, OutputLevel.INFO) gives you the same server as an object inside tests or tools.

Examples

cd build/site && jwebserver -p 9000 -o verbose
# equivalent long form:
java -m jdk.httpserver -p 9000
var server = SimpleFileServer.createFileServer(
    new InetSocketAddress(9000), Path.of("build/site"),
    SimpleFileServer.OutputLevel.INFO);
server.start();

Related

  • JDK & tools — parent catalogue of the JDK toolchain.
  • jshell — same spirit: JDK-bundled convenience for quick experiments.
  • REST — the real HTTP service stacks to use once static files are not enough.
  • API design — designing actual HTTP APIs, beyond file serving.