Quickly Spin Up a Simple Java 18 Web Server with jwebserver
This article introduces Java 18’s JEP 408 Simple Web Server, explains its purpose and limitations, walks through creating an HTML page, demonstrates launching the server via command line with various options, and shows how to access and verify the served content.
In March 2022 Java was updated to version 18, which includes JEP 408: Simple Web Server, a lightweight tool for serving static resources.
Simple Web Server Overview
The server is intended for testing and teaching, not as a replacement for full‑featured servers like Jetty or Nginx.
Key Characteristics
Designed for testing and teaching, not a replacement for Jetty, Nginx, etc.
No authentication, access control, or encryption.
Supports only HTTP/1.1; HTTPS is not available.
Handles only GET and HEAD requests.
Can be started via command line or Java class.
Prepare HTML Page
Step 1: Create a folder, e.g., jwebserver.
Step 2: Create an index.html file inside the folder.
Step 3: Add any HTML content you wish to serve.
Start Server from Command Line
Open a terminal and run: $ jwebserver The server starts quickly and prints output similar to the screenshot below.
Visit http://127.0.0.1:8000/ to see the HTML page you prepared. http://127.0.0.1:8000/ The terminal also shows request logs:
127.0.0.1 - - [20/Apr/2022:00:10:58 +0800] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [20/Apr/2022:00:10:58 +0800] "GET /banner-spring-boot.png HTTP/1.1" 200 -Optional Parameters
-h or -? or --help
Prints the help message and exits.
-b addr or --bind-address addr
Bind address (default 127.0.0.1 or ::1). Use -b 0.0.0.0 for all interfaces.
-d dir or --directory dir
Directory to serve (default current directory).
-o level or --output level
Output format: none | info | verbose (default info).
-p port or --port port
Listening port (default 8000).
--version
Prints version information.Most useful flags: -b: bind IP address. -p: port to listen on. -d: directory to serve. -o: console output level.
A typical command combining these options looks like: jwebserver -p 9000 -d / -b 127.0.0.1 -o info This starts a server on port 9000, serving the root directory, bound to 127.0.0.1, with info‑level console output.
Visiting http://127.0.0.1:9000/ displays the directory listing, as shown in the screenshot below.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
