Run a simple web server with Java using jwebserver

We often use the Java server runtime to run Java web applications such as Tomcat, Jetty, … From Java version 18, by default, Java also supports us to run a server runtime using the jwebserver command. By default, the jwebserver command will run a web server with the address http://127.0.0.1:8000/ and when you go to this address, it will display a list of directories and files in the directory you ran this command.

My example is as follows:

Result:

There are four options that you can use to change the IP address the server will run on (option -b), the port (option -p), the server’s root directory (option -d), and the output log format (option – o). Output log format can be none, info, verbose, default is info.

For example, I can run the command as follows:

Result:

When requesting to http://127.0.0.1:8000/, you will see a lot of log lines displayed as follows:

That’s because I used the output log format as verbose!

I also have to tell you that, the server runtime running with this jwebserver command currently has many limitations. It only supports HTTP/1.1, not HTTPS yet, and only GET and HEAD HTTP methods are supported!

Add Comment