Java18 introduced a Simple web server class and command line tool to start and run a web server.

It has limited support for serving static files such as HTML, javascript, and images and does not support CGI or Servlets.

It is not a full-fledged webserver to replace commercially available web servers. It just provides a webserver with development, testing, and ad-hoc applications.

Webserver Limitations

It supports HTTP HEAD and gets requests All the other requests give an error message “501 - Not Implemented or a 405 - Not Allowed response” Supports HTTP/1.1, and does not support HTTPS.

How to create a Simple Web Server with a command line

With JDK18 installed, You can open Commandline.

Run the below command to Start a Simple web server

$ Jwebserver


It starts the web server and prints a message with the Hostname and port number. The default port is 8000

You can change the port using -p option below

Jwebserver -p 8100

Similarly, You can change the hostname using the -b option as given below

jwebserver -b

Static files are accessible, and these are served from the current directory.

You can change the directory using the -d option.

Create a web server with Java API

Here is an JEP about this feature.