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

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

It is not full fledged webserver to replace commerical avialiable webservers. It just provides an webserver with development, testing and adhoc applications.

Webserver Limitations

It supports HTTP HEAD and GET requests All the other requests gives 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 command line

With JDK18 installed, You can open Commandline.

Run the below command to Start Simple web server

$ Jwebserver


URL: http://127.0.0.1:8000/

It starts webserver and print message with Hostname and port number. Default port is 8000

You can change the port using -p option as below

Jwebserver -p 8100

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

jwebserver -b 0.0.0.0

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

You can change the directory using -d option

Create a webserver with Java API

Here is an JEP about this feature.